| 115 | for i, xi in enumerate(self.x_space): self.x[i] = xi |
| 116 | |
| 117 | class svm_parameter(Structure): |
| 118 | _names = ["svm_type", "kernel_type", "degree", "gamma", "coef0", |
| 119 | "cache_size", "eps", "C", "nr_weight", "weight_label", "weight", |
| 120 | "nu", "p", "shrinking", "probability"] |
| 121 | _types = [c_int, c_int, c_int, c_double, c_double, |
| 122 | c_double, c_double, c_double, c_int, POINTER(c_int), POINTER(c_double), |
| 123 | c_double, c_double, c_int, c_int] |
| 124 | _fields_ = genFields(_names, _types) |
| 125 | |
| 126 | def __init__(self, options = None): |
| 127 | if options == None: |
| 128 | options = '' |
| 129 | self.parse_options(options) |
| 130 | |
| 131 | def __str__(self): |
| 132 | s = '' |
| 133 | attrs = svm_parameter._names + list(self.__dict__.keys()) |
| 134 | values = map(lambda attr: getattr(self, attr), attrs) |
| 135 | for attr, val in zip(attrs, values): |
| 136 | s += (' %s: %s\n' % (attr, val)) |
| 137 | s = s.strip() |
| 138 | |
| 139 | return s |
| 140 | |
| 141 | def set_to_default_values(self): |
| 142 | self.svm_type = C_SVC; |
| 143 | self.kernel_type = RBF |
| 144 | self.degree = 3 |
| 145 | self.gamma = 0 |
| 146 | self.coef0 = 0 |
| 147 | self.nu = 0.5 |
| 148 | self.cache_size = 100 |
| 149 | self.C = 1 |
| 150 | self.eps = 0.001 |
| 151 | self.p = 0.1 |
| 152 | self.shrinking = 1 |
| 153 | self.probability = 0 |
| 154 | self.nr_weight = 0 |
| 155 | self.weight_label = (c_int*0)() |
| 156 | self.weight = (c_double*0)() |
| 157 | self.cross_validation = False |
| 158 | self.nr_fold = 0 |
| 159 | self.print_func = None |
| 160 | |
| 161 | def parse_options(self, options): |
| 162 | if isinstance(options, list): |
| 163 | argv = options |
| 164 | elif isinstance(options, str): |
| 165 | argv = options.split() |
| 166 | else: |
| 167 | raise TypeError("arg 1 should be a list or a str.") |
| 168 | self.set_to_default_values() |
| 169 | self.print_func = cast(None, PRINT_STRING_FUN) |
| 170 | weight_label = [] |
| 171 | weight = [] |
| 172 | |
| 173 | i = 0 |
| 174 | while i < len(argv): |