1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // This file contains a few utilities for MulticlassPA
18 
19 #include "learning/multiclass_pa/util.h"
20 
21 #include <string>
22 
23 #include "learning/multiclass_pa/multiclass_pa.h"
24 #include "learning/multiclass_pa/multiclass_pa_max.h"
25 #include "learning/multiclass_pa/multiclass_pa_opt.h"
26 #include "learning/multiclass_pa/multiclass_warp.h"
27 #include "strings/strutil.h"
28 
29 namespace learning_multiclass_pa {
30 
CreateMulticlassPA(const string & version,int32 num_classes,int32 num_dimensions,float aggressiveness)31 MulticlassPA* CreateMulticlassPA(const string& version,
32                                  int32 num_classes,
33                                  int32 num_dimensions,
34                                  float aggressiveness) {
35   MulticlassPA* machine = NULL;
36   if (StringCaseEqual(version, "max")) {
37     machine = reinterpret_cast<MulticlassPA*>(
38       new MulticlassPAMax(num_classes, num_dimensions, aggressiveness));
39   } else if (StringCaseEqual(version, "opt")) {
40     machine = reinterpret_cast<MulticlassPA*>(
41       new MulticlassPAOpt(num_classes, num_dimensions, aggressiveness));
42   } else if (StringCaseEqual(version, "random")) {
43     machine = new MulticlassPA(num_classes, num_dimensions, aggressiveness);
44   } else if (StringCaseEqual(version, "warp")) {
45     machine = reinterpret_cast<MulticlassPA*>(
46       new MulticlassWarp(num_classes, num_dimensions, aggressiveness));
47   } else {
48     LOG(ERROR) << "Machine type (" << version << ") unknown";
49   }
50   return machine;
51 }
52 }  // namespace learning_multiclass_pa
53