def setUp(self):
     super(RandomForestClassifierTest, self).setUp()
     self.porter = Porter(language='js')
     clf = RandomForestClassifier(n_estimators=100, random_state=0)
     self._port_model(clf)
示例#2
0
# %% [markdown]
# ### Train classifier

# %%
from sklearn.neighbors import KNeighborsClassifier

clf = KNeighborsClassifier(algorithm='brute', n_neighbors=3, weights='uniform')
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='java')
output = porter.export(export_data=True)

print(output)

# %% [markdown]
# ### Run classification in Java

# %%
# Save classifier:
# with open('KNeighborsClassifier.java', 'w') as f:
#     f.write(output)

# Check model data:
# $ cat data.json
示例#3
0
# -*- coding: utf-8 -*-

from sklearn.datasets import load_iris
from sklearn.naive_bayes import GaussianNB
from sklearn_porter import Porter

iris_data = load_iris()
X, y = iris_data.data, iris_data.target

clf = GaussianNB()
clf.fit(X, y)

output = Porter(clf, language='js').export()
# output = Porter(clf, language='java').export()
print(output)
"""
var Brain = function() {

    this.predict = function(atts) {
    
        var priors = [0.33333333333333331, 0.33333333333333331, 0.33333333333333331];
        var sigmas = [[0.12176400309242481, 0.14227600309242491, 0.029504003092424898, 0.011264003092424885], [0.26110400309242499, 0.096500003092424902, 0.21640000309242502, 0.038324003092424869], [0.39625600309242481, 0.10192400309242496, 0.29849600309242508, 0.073924003092424875]];
        var thetas = [[5.0059999999999993, 3.4180000000000006, 1.464, 0.24399999999999991], [5.9359999999999999, 2.7700000000000005, 4.2599999999999998, 1.3259999999999998], [6.5879999999999983, 2.9739999999999998, 5.5519999999999996, 2.0259999999999998]];
        var likelihoods = new Array(3);
    
        for (var i = 0; i < 3; i++) {
            var sum = 0.;
            for (var j = 0; j < 4; j++) {
                sum += Math.log(2. * Math.PI * sigmas[i][j]);
            }
            var nij = -0.5 * sum;
示例#4
0
# -*- coding: utf-8 -*-

import subprocess as subp
from sklearn import svm
from sklearn.datasets import load_iris
from sklearn_porter import Porter

iris_data = load_iris()
X, y = iris_data.data, iris_data.target
clf = svm.LinearSVC(C=1., random_state=0)
clf.fit(X, y)

data = Porter(clf, language='c').export(details=True)

# Save model:
with open(data.get('filename'), 'w') as f:
    f.write(data.get('model'))

# Compile model:
command = data.get('cmd').get('compilation')
subp.call(command, shell=True)

# Use the model:
features = ' '.join([repr(x) for x in X[0]])
command = '%s %s' % (data.get('cmd').get('execution'), features)
prediction = subp.check_output(command, shell=True)

print('Ported classifier: %s' % prediction)  # class: 0
print('Original classifier: %s' % clf.predict([X[0]])[0])  # class: 0
示例#5
0
文件: convert.py 项目: BobAnkh/pitree
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_graphviz
from sklearn.externals.six import StringIO
import pydotplus
import pickle as pk
import csv
import pensieve
import pensiedt
import robustmpc
import robustmdt
import hotdash
import hotdadt
import argparse
import load_trace
import fixed_env as env
import fixed_env_hotdash as env_hotdash
from multiprocessing import Pool
import time
from sklearn.datasets import load_iris
from sklearn.tree import tree
from sklearn_porter import Porter


with open('./results/decision_tree/robustmpc_lin_mixed_500.pk3','rb') as f:
  best_tree=pk.load(f)
porter=Porter(best_tree,language='js')
output=porter.export(embed_data=True)
with open('./results/decision_tree/dt3','w') as fp:
  fp.write(output)
# print(output)
示例#6
0
from sklearn.datasets import load_iris
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn_porter import Porter

iris_data = load_iris()
X = iris_data.data
y = iris_data.target

base_estimator = DecisionTreeClassifier(max_depth=4, random_state=0)
clf = AdaBoostClassifier(base_estimator=base_estimator,
                         n_estimators=100,
                         random_state=0)
clf.fit(X, y)

porter = Porter(clf)
output = porter.export(export_data=True)
print(output)
"""
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


class AdaBoostClassifier {
示例#7
0
# -*- coding: utf-8 -*-

from sklearn.datasets import load_iris
from sklearn.naive_bayes import BernoulliNB
from sklearn_porter import Porter

iris_data = load_iris()
X, y = iris_data.data, iris_data.target

clf = BernoulliNB()
clf.fit(X, y)

output = Porter(clf).export()
# output = Porter(clf, language='java').export()
print(output)
"""
class Brain {

    public static int predict(double[] atts) {
        if (atts.length != 4) {
            return -1;
        }
        int i, j;

        double[] priors = {-1.0986122886681096, -1.0986122886681096, -1.0986122886681096};
        double[][] negProbs = {{-3.9512437185814138, -3.9512437185814138, -3.9512437185814138, -3.9512437185814138}, {-3.9512437185814138, -3.9512437185814138, -3.9512437185814138, -3.9512437185814138}, {-3.9512437185814138, -3.9512437185814138, -3.9512437185814138, -3.9512437185814138}};
        double[][] delProbs = {{3.931825632724312, 3.931825632724312, 3.931825632724312}, {3.931825632724312, 3.931825632724312, 3.931825632724312}, {3.931825632724312, 3.931825632724312, 3.931825632724312}, {3.931825632724312, 3.931825632724312, 3.931825632724312}};

        double[] jll = new double[3];
        for (i = 0; i < 3; i++) {
            double sum = 0.;
示例#8
0
 def setUp(self):
     super(SVCTest, self).setUp()
     self.porter = Porter(language='java')
     clf = SVC(C=1., kernel='rbf', gamma=0.001, random_state=0)
     self.set_classifier(clf)
示例#9
0
# %%
from sklearn.datasets import load_iris

iris_data = load_iris()

X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)

# %% [markdown]
# ### Train classifier

# %%
from sklearn.tree import tree

clf = tree.DecisionTreeClassifier()
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='ruby')
output = porter.export()

print(output)
示例#10
0
 def test_porter_args_language(self):
     """Test invalid programming language."""
     self.assertRaises(AttributeError,
                       lambda: Porter(self.estimator, language='invalid'))
示例#11
0
# -*- coding: utf-8 -*-

from sklearn import svm
from sklearn.datasets import load_iris
from sklearn_porter import Porter

iris_data = load_iris()
X = iris_data.data
y = iris_data.target

clf = svm.LinearSVC(C=1., random_state=0)
clf.fit(X, y)

porter = Porter(clf, language='js')
output = porter.export()
print(output)
"""
var LinearSVC = function(coefficients, intercepts) {

    this.coefficients = coefficients;
    this.intercepts = intercepts;

    this.predict = function(features) {
        var classIdx = 0,
            classVal = Number.NEGATIVE_INFINITY,
            prob = 0.;
        for (var i = 0, il = this.intercepts.length; i < il; i++) {
            prob = 0.;
            for (var j = 0, jl = this.coefficients[0].length; j < jl; j++) {
                prob += this.coefficients[i][j] * features[j];
            }
示例#12
0
 def test_porter_args_method(self):
     """Test invalid method name."""
     self.assertRaises(AttributeError,
                       lambda: Porter(self.estimator, method='invalid'))
示例#13
0
import subprocess as subp

from sklearn import svm
from sklearn.datasets import load_iris

from sklearn_porter import Porter

X, y = load_iris(return_X_y=True)
clf = svm.LinearSVC(C=1., random_state=0)
clf.fit(X, y)

# Cheese!

data = Porter(language='c', with_details=True).port(clf)

# Save model:
with open(data.get('filename'), 'w') as file:
    file.write(data.get('model'))

# Compile model:
command = data.get('compiling_cmd')
subp.call(command, shell=True)

# Use the model:
features = ' '.join([repr(x) for x in X[0]])
command = '%s %s' % (data.get('execution_cmd'), features)
prediction = subp.check_output(command, shell=True)

print('Ported classifier: %s' % prediction)  # class: 0
print('Original classifier: %s' % clf.predict([X[0]])[0])  # class: 0
示例#14
0
 def setUp(self):
     super(LinearSVCTest, self).setUp()
     self.porter = Porter(language='c')
     self._port_model(LinearSVC(C=1., random_state=0))
ry_test = y_test


model = make_pipeline(StandardScaler(), svm.LinearSVC(random_state=0, tol=1e-5))
model.fit(rx_train, ry_train)
label=model.predict(rx_test)

import pickle, os
pkl_filename = "svm_linesvc.pkl"
with open(pkl_filename, 'wb') as file:
    pickle.dump(model, file)
print("train model saved: {} size: {}".format(pkl_filename, os.path.getsize(pkl_filename)))

from sklearn_porter import Porter

porter = Porter(model, language='c')
output = porter.export()
cpt_filename = "svm_linesvc.c"
with open(cpt_filename, 'w') as file:
    n = file.write(output)
    print("tran model save in c: {} len: {}".format(cpt_filename, len(output)))

print(classification_report(label, ry_test, target_names=[lb for lb in labels.values()]))

conf_mat = confusion_matrix(label, ry_test)

plt.style.use('bmh')
fig = plt.figure(figsize=(6,6))
width = np.shape(conf_mat)[1]
height = np.shape(conf_mat)[0]
示例#16
0
from sklearn import svm
from sklearn.datasets import load_iris

from sklearn_porter import Porter

X, y = load_iris(return_X_y=True)
clf = svm.LinearSVC(C=1., random_state=0)
clf.fit(X, y)

# Cheese!

result = Porter().port(clf)
# model = Porter(language='java').port(clf)
print(result)
"""
class Tmp {

    public static int predict(float[] atts) {
        if (atts.length != 4) { return -1; }

        double[][] coefs = {{0.18424209458473811, 0.45123000025163923, -0.80794587716737576, -0.45071660033253858}, {0.052877455748516447, -0.89214995228605254, 0.40398084459610972, -0.9376821661447452}, {-0.85070784319293802, -0.98670214922204336, 1.381010448739191, 1.8654095662423917}};
        double[] inters = {0.10956266406702335, 1.6636707776739579, -1.7096109416521363};

        int class_idx = -1;
        double class_val = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < 3; i++) {
            double prob = 0.;
            for (int j = 0; j < 4; j++) {
                prob += coefs[i][j] * atts[j];
            }
            if (prob + inters[i] > class_val) {
示例#17
0
# %%
from sklearn.datasets import load_iris

iris_data = load_iris()

X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)

# %% [markdown]
# ### Train classifier

# %%
from sklearn.tree import tree

clf = tree.DecisionTreeClassifier()
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='go')
output = porter.export()

print(output)
示例#18
0
 def setUp(self):
     super(ExtraTreesClassifierTest, self).setUp()
     self.porter = Porter(language='java')
     self.set_classifier(ExtraTreesClassifier(random_state=0))
 def setUp(self):
     super(ExtraTreesClassifierTest, self).setUp()
     self.porter = Porter(language='c')
     self._port_model(ExtraTreesClassifier(random_state=0))
示例#20
0
 def setUp(self):
     super(BernoulliNBTest, self).setUp()
     self.porter = Porter(language='java')
     self._port_model(BernoulliNB())
示例#21
0
        name: metric(y_test, y_pred, average='weighted')
        for name, metric in metrics.items()
    }
    model_scores['estimator'] = estimator_name
    scores = scores.append(model_scores, ignore_index=True)
scores.set_index('estimator')
# %%
scores.plot.bar(x='estimator', rot=20)
plt.show()

# %% [markdown]

# ## Test classifier
estimator = RandomForestClassifier(n_estimators=40, random_state=42)
estimator.fit(x_train, y_train)
y_pred = estimator.predict(x_test)
report = classification_report(y_test, y_pred)  # , output_dict=True)
print(report)
# report = pd.DataFrame(report)
# report['estimator'] = 'decision_tree'

# %% [markdown]

# ## Export model
# Use sklearn porter to export trained model to java script.

porter = Porter(estimator, language='js')
output = porter.export(embed_data=False)
with open('model.js', 'w') as file:
    file.write(output)
示例#22
0
from sklearn_porter import Porter

samples = load_diabetes()
X, y = samples.data, samples.target

reg = MLPRegressor(activation='logistic',
                   hidden_layer_sizes=[30, 20, 30],
                   max_iter=500,
                   alpha=1e-4,
                   solver='sgd',
                   tol=1e-4,
                   random_state=1,
                   learning_rate_init=.1)
reg.fit(X, y)

porter = Porter(reg, language='js')
output = porter.export()
print(output)
"""
var MLPRegressor = function(hidden, layers, weights, bias) {

    this.hidden = hidden.toUpperCase();
    this.network = new Array(layers.length + 1);
    for (var i = 0, l = layers.length; i < l; i++) {
        this.network[i + 1] = new Array(layers[i]).fill(0.);
    }
    this.weights = weights;
    this.bias = bias;

    var compute = function(activation, v, nLayers) {
        switch (activation) {
示例#23
0
X = shuffle(X, random_state=0)
y = shuffle(y, random_state=0)

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.4, random_state=5)

clf = MLPClassifier(
    activation='relu', hidden_layer_sizes=50, max_iter=500, alpha=1e-4,
    solver='sgd', tol=1e-4, random_state=1, learning_rate_init=.1)

clf.fit(X_train, y_train)

# Cheese!

result = Porter(language='js').port(clf)
print(result)

"""
// Array.prototype.fill polyfill:
[].fill||(Array.prototype.fill=function(a){for(var b=Object(this),c=parseInt(b.length,10),d=arguments[1],e=parseInt(d,10)||0,f=0>e?Math.max(c+e,0):Math.min(e,c),g=arguments[2],h=void 0===g?c:parseInt(g)||0,i=0>h?Math.max(c+h,0):Math.min(h,c);i>f;f++)b[f]=a;return b});

var Tmp = function(atts) {

    // Type: relu
    var hidden_activation = function(v) {
        for (var i = 0, l = v.length; i < l; i++) {
            v[i] = Math.max(0, v[i]);
        }
        return v;
    };
示例#24
0
 def setUp(self):
     super(SVCTest, self).setUp()
     self.porter = Porter(language='c')
     clf = NuSVC(kernel='rbf', gamma=0.001, random_state=0)
     self._port_model(clf)
示例#25
0
        varianceArray, xZeroCrossingsArray, yZeroCrossingsArray,
        zZeroCrossingsArray
    ])
    X.append(tempArray)
    Y.append(row[4])

file.close()
X = np.asarray(X)
samples, x, y = X.shape
X = X.reshape((samples, x * y))
print(X.shape)
print(len(Y))

classifier = svm.SVC(kernel='rbf', C=100, gamma=0.25)
classifier.fit(X, Y)
porter = Porter(classifier, language='java')
output = porter.export()

file = open("Dataset.csv", "r")
reader = csv.reader(file)
next(reader)
correctCounter = 0
lineCounter = 0

for row in reader:
    varianceArray = np.fromstring(row[0], dtype=np.float, sep=',')
    xZeroCrossingsArray = np.fromstring(row[1], dtype=np.float, sep=',')
    yZeroCrossingsArray = np.fromstring(row[2], dtype=np.float, sep=',')
    zZeroCrossingsArray = np.fromstring(row[3], dtype=np.float, sep=',')
    predictionArray = np.array([
        varianceArray, xZeroCrossingsArray, yZeroCrossingsArray,
示例#26
0
# %%
from sklearn.datasets import load_iris

iris_data = load_iris()

X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)

# %% [markdown]
# ### Train classifier

# %%
from sklearn import svm

clf = svm.NuSVC(gamma=0.001, kernel='rbf', random_state=0)
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='php')
output = porter.export()

print(output)
示例#27
0
#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
#clf = DecisionTreeClassifier(min_samples_leaf=3, min_samples_split=2, criterion='entropy')
clf = clf = DecisionTreeClassifier(min_samples_leaf=clf.best_params_['min_samples_leaf'], min_samples_split=clf.best_params_['min_samples_split'], criterion='entropy')
#clf = clf.fit(X_train, y_train)

print('length of dataset before SMOTE: ', len(X))

smt = SMOTE()
X_train, y_train = smt.fit_sample(X, y)

print('length of dataset after SMOTE: ', len(X_train))

selector = RFECV(clf, step=1, cv=10, scoring=metrics.make_scorer(metrics.f1_score))
selector = selector.fit(X_train, y_train)

print(selector.support_)
print(selector.ranking_)

y_pred = selector.predict(X)

print('f1:', metrics.f1_score(y_pred, y))
print('IoU:', metrics.jaccard_score(y_pred, y))
print('AuC:', metrics.roc_auc_score(y_pred, y))

porter = Porter(selector.estimator_, language='js')
output = porter.export(embed_data=True)

with open(os.path.join(args.out_dir, 'model.js'), mode='w+', encoding='utf8') as f:
    f.write('export ' + output)
示例#28
0
        fig, ax = plt.subplots()
        xx, yy = grid(train_x)
        plot_contours(ax, clf, xx, yy, cmap=plt.cm.coolwarm, alpha=0.8)

        ax.set_xlim(-3, 3)
        ax.set_ylim(-3, 3)
        ax.scatter(train_x_sc[:, 1],
                   train_x_sc[:, 0],
                   c=train_y,
                   cmap=plt.cm.coolwarm,
                   s=20,
                   edgecolors='k')

        ax.set_xlabel("Non-zero elements")
        ax.set_ylabel("Rows")
        plt.show()

    if args.test is not None:
        test_frame = pd.read_csv(args.test, sep=' ')
        test_x, test_y = get_data(test_frame)
        preds = clf.predict(scaler.transform(np.log(test_x)))
        results = (np.array(preds) == np.array(test_y))
        acc = 100 * sum(results) / len(results)
        print(f"Test Accuracy: {acc:.3f}%")

    if args.code:
        p = Porter(clf, language='C')
        print(p.export(embed_data=True))
        print("row mean: {}, nnz mean: {}".format(*scaler.mean_))
        print("row scale: {}, nnz scale: {}".format(*scaler.scale_))
示例#29
0
# %% [markdown]
# ### Train classifier

# %%
from sklearn import svm

clf = svm.LinearSVC(C=1., random_state=0)
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='c')
output = porter.export()

print(output)

# %% [markdown]
# ### Run classification in C

# %%
# Save model:
# with open('linearsvc.c', 'w') as f:
#     f.write(output)

# Compile model:
# $ gcc linearsvc.c -std=c99 -lm -o linearsvc
示例#30
0
# -*- coding: utf-8 -*-

from sklearn import svm
from sklearn.datasets import load_iris
from sklearn_porter import Porter

iris_data = load_iris()
X, y = iris_data.data, iris_data.target

clf = svm.SVC(C=1., gamma=0.001, kernel='rbf', random_state=0)
clf.fit(X, y)

output = Porter(clf, language='php').export()
print(output)
"""
<?php

class Brain {

    public static function predict($atts) {

        $n_svs = [50, 50, 50];
        $svs = [[5.0999999999999996, 3.5, 1.3999999999999999, 0.20000000000000001], [4.9000000000000004, 3.0, 1.3999999999999999, 0.20000000000000001], [4.7000000000000002, 3.2000000000000002, 1.3, 0.20000000000000001], [4.5999999999999996, 3.1000000000000001, 1.5, 0.20000000000000001], [5.0, 3.6000000000000001, 1.3999999999999999, 0.20000000000000001], [5.4000000000000004, 3.8999999999999999, 1.7, 0.40000000000000002], [4.5999999999999996, 3.3999999999999999, 1.3999999999999999, 0.29999999999999999], [5.0, 3.3999999999999999, 1.5, 0.20000000000000001], [4.4000000000000004, 2.8999999999999999, 1.3999999999999999, 0.20000000000000001], [4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001], [5.4000000000000004, 3.7000000000000002, 1.5, 0.20000000000000001], [4.7999999999999998, 3.3999999999999999, 1.6000000000000001, 0.20000000000000001], [4.7999999999999998, 3.0, 1.3999999999999999, 0.10000000000000001], [4.2999999999999998, 3.0, 1.1000000000000001, 0.10000000000000001], [5.7999999999999998, 4.0, 1.2, 0.20000000000000001], [5.7000000000000002, 4.4000000000000004, 1.5, 0.40000000000000002], [5.4000000000000004, 3.8999999999999999, 1.3, 0.40000000000000002], [5.0999999999999996, 3.5, 1.3999999999999999, 0.29999999999999999], [5.7000000000000002, 3.7999999999999998, 1.7, 0.29999999999999999], [5.0999999999999996, 3.7999999999999998, 1.5, 0.29999999999999999], [5.4000000000000004, 3.3999999999999999, 1.7, 0.20000000000000001], [5.0999999999999996, 3.7000000000000002, 1.5, 0.40000000000000002], [4.5999999999999996, 3.6000000000000001, 1.0, 0.20000000000000001], [5.0999999999999996, 3.2999999999999998, 1.7, 0.5], [4.7999999999999998, 3.3999999999999999, 1.8999999999999999, 0.20000000000000001], [5.0, 3.0, 1.6000000000000001, 0.20000000000000001], [5.0, 3.3999999999999999, 1.6000000000000001, 0.40000000000000002], [5.2000000000000002, 3.5, 1.5, 0.20000000000000001], [5.2000000000000002, 3.3999999999999999, 1.3999999999999999, 0.20000000000000001], [4.7000000000000002, 3.2000000000000002, 1.6000000000000001, 0.20000000000000001], [4.7999999999999998, 3.1000000000000001, 1.6000000000000001, 0.20000000000000001], [5.4000000000000004, 3.3999999999999999, 1.5, 0.40000000000000002], [5.2000000000000002, 4.0999999999999996, 1.5, 0.10000000000000001], [5.5, 4.2000000000000002, 1.3999999999999999, 0.20000000000000001], [4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001], [5.0, 3.2000000000000002, 1.2, 0.20000000000000001], [5.5, 3.5, 1.3, 0.20000000000000001], [4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001], [4.4000000000000004, 3.0, 1.3, 0.20000000000000001], [5.0999999999999996, 3.3999999999999999, 1.5, 0.20000000000000001], [5.0, 3.5, 1.3, 0.29999999999999999], [4.5, 2.2999999999999998, 1.3, 0.29999999999999999], [4.4000000000000004, 3.2000000000000002, 1.3, 0.20000000000000001], [5.0, 3.5, 1.6000000000000001, 0.59999999999999998], [5.0999999999999996, 3.7999999999999998, 1.8999999999999999, 0.40000000000000002], [4.7999999999999998, 3.0, 1.3999999999999999, 0.29999999999999999], [5.0999999999999996, 3.7999999999999998, 1.6000000000000001, 0.20000000000000001], [4.5999999999999996, 3.2000000000000002, 1.3999999999999999, 0.20000000000000001], [5.2999999999999998, 3.7000000000000002, 1.5, 0.20000000000000001], [5.0, 3.2999999999999998, 1.3999999999999999, 0.20000000000000001], [7.0, 3.2000000000000002, 4.7000000000000002, 1.3999999999999999], [6.4000000000000004, 3.2000000000000002, 4.5, 1.5], [6.9000000000000004, 3.1000000000000001, 4.9000000000000004, 1.5], [5.5, 2.2999999999999998, 4.0, 1.3], [6.5, 2.7999999999999998, 4.5999999999999996, 1.5], [5.7000000000000002, 2.7999999999999998, 4.5, 1.3], [6.2999999999999998, 3.2999999999999998, 4.7000000000000002, 1.6000000000000001], [4.9000000000000004, 2.3999999999999999, 3.2999999999999998, 1.0], [6.5999999999999996, 2.8999999999999999, 4.5999999999999996, 1.3], [5.2000000000000002, 2.7000000000000002, 3.8999999999999999, 1.3999999999999999], [5.0, 2.0, 3.5, 1.0], [5.9000000000000004, 3.0, 4.2000000000000002, 1.5], [6.0, 2.2000000000000002, 4.0, 1.0], [6.0999999999999996, 2.8999999999999999, 4.7000000000000002, 1.3999999999999999], [5.5999999999999996, 2.8999999999999999, 3.6000000000000001, 1.3], [6.7000000000000002, 3.1000000000000001, 4.4000000000000004, 1.3999999999999999], [5.5999999999999996, 3.0, 4.5, 1.5], [5.7999999999999998, 2.7000000000000002, 4.0999999999999996, 1.0], [6.2000000000000002, 2.2000000000000002, 4.5, 1.5], [5.5999999999999996, 2.5, 3.8999999999999999, 1.1000000000000001], [5.9000000000000004, 3.2000000000000002, 4.7999999999999998, 1.8], [6.0999999999999996, 2.7999999999999998, 4.0, 1.3], [6.2999999999999998, 2.5, 4.9000000000000004, 1.5], [6.0999999999999996, 2.7999999999999998, 4.7000000000000002, 1.2], [6.4000000000000004, 2.8999999999999999, 4.2999999999999998, 1.3], [6.5999999999999996, 3.0, 4.4000000000000004, 1.3999999999999999], [6.7999999999999998, 2.7999999999999998, 4.7999999999999998, 1.3999999999999999], [6.7000000000000002, 3.0, 5.0, 1.7], [6.0, 2.8999999999999999, 4.5, 1.5], [5.7000000000000002, 2.6000000000000001, 3.5, 1.0], [5.5, 2.3999999999999999, 3.7999999999999998, 1.1000000000000001], [5.5, 2.3999999999999999, 3.7000000000000002, 1.0], [5.7999999999999998, 2.7000000000000002, 3.8999999999999999, 1.2], [6.0, 2.7000000000000002, 5.0999999999999996, 1.6000000000000001], [5.4000000000000004, 3.0, 4.5, 1.5], [6.0, 3.3999999999999999, 4.5, 1.6000000000000001], [6.7000000000000002, 3.1000000000000001, 4.7000000000000002, 1.5], [6.2999999999999998, 2.2999999999999998, 4.4000000000000004, 1.3], [5.5999999999999996, 3.0, 4.0999999999999996, 1.3], [5.5, 2.5, 4.0, 1.3], [5.5, 2.6000000000000001, 4.4000000000000004, 1.2], [6.0999999999999996, 3.0, 4.5999999999999996, 1.3999999999999999], [5.7999999999999998, 2.6000000000000001, 4.0, 1.2], [5.0, 2.2999999999999998, 3.2999999999999998, 1.0], [5.5999999999999996, 2.7000000000000002, 4.2000000000000002, 1.3], [5.7000000000000002, 3.0, 4.2000000000000002, 1.2], [5.7000000000000002, 2.8999999999999999, 4.2000000000000002, 1.3], [6.2000000000000002, 2.8999999999999999, 4.2999999999999998, 1.3], [5.0999999999999996, 2.5, 3.0, 1.1000000000000001], [5.7000000000000002, 2.7999999999999998, 4.0999999999999996, 1.3], [6.2999999999999998, 3.2999999999999998, 6.0, 2.5], [5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999], [7.0999999999999996, 3.0, 5.9000000000000004, 2.1000000000000001], [6.2999999999999998, 2.8999999999999999, 5.5999999999999996, 1.8], [6.5, 3.0, 5.7999999999999998, 2.2000000000000002], [7.5999999999999996, 3.0, 6.5999999999999996, 2.1000000000000001], [4.9000000000000004, 2.5, 4.5, 1.7], [7.2999999999999998, 2.8999999999999999, 6.2999999999999998, 1.8], [6.7000000000000002, 2.5, 5.7999999999999998, 1.8], [7.2000000000000002, 3.6000000000000001, 6.0999999999999996, 2.5], [6.5, 3.2000000000000002, 5.0999999999999996, 2.0], [6.4000000000000004, 2.7000000000000002, 5.2999999999999998, 1.8999999999999999], [6.7999999999999998, 3.0, 5.5, 2.1000000000000001], [5.7000000000000002, 2.5, 5.0, 2.0], [5.7999999999999998, 2.7999999999999998, 5.0999999999999996, 2.3999999999999999], [6.4000000000000004, 3.2000000000000002, 5.2999999999999998, 2.2999999999999998], [6.5, 3.0, 5.5, 1.8], [7.7000000000000002, 3.7999999999999998, 6.7000000000000002, 2.2000000000000002], [7.7000000000000002, 2.6000000000000001, 6.9000000000000004, 2.2999999999999998], [6.0, 2.2000000000000002, 5.0, 1.5], [6.9000000000000004, 3.2000000000000002, 5.7000000000000002, 2.2999999999999998], [5.5999999999999996, 2.7999999999999998, 4.9000000000000004, 2.0], [7.7000000000000002, 2.7999999999999998, 6.7000000000000002, 2.0], [6.2999999999999998, 2.7000000000000002, 4.9000000000000004, 1.8], [6.7000000000000002, 3.2999999999999998, 5.7000000000000002, 2.1000000000000001], [7.2000000000000002, 3.2000000000000002, 6.0, 1.8], [6.2000000000000002, 2.7999999999999998, 4.7999999999999998, 1.8], [6.0999999999999996, 3.0, 4.9000000000000004, 1.8], [6.4000000000000004, 2.7999999999999998, 5.5999999999999996, 2.1000000000000001], [7.2000000000000002, 3.0, 5.7999999999999998, 1.6000000000000001], [7.4000000000000004, 2.7999999999999998, 6.0999999999999996, 1.8999999999999999], [7.9000000000000004, 3.7999999999999998, 6.4000000000000004, 2.0], [6.4000000000000004, 2.7999999999999998, 5.5999999999999996, 2.2000000000000002], [6.2999999999999998, 2.7999999999999998, 5.0999999999999996, 1.5], [6.0999999999999996, 2.6000000000000001, 5.5999999999999996, 1.3999999999999999], [7.7000000000000002, 3.0, 6.0999999999999996, 2.2999999999999998], [6.2999999999999998, 3.3999999999999999, 5.5999999999999996, 2.3999999999999999], [6.4000000000000004, 3.1000000000000001, 5.5, 1.8], [6.0, 3.0, 4.7999999999999998, 1.8], [6.9000000000000004, 3.1000000000000001, 5.4000000000000004, 2.1000000000000001], [6.7000000000000002, 3.1000000000000001, 5.5999999999999996, 2.3999999999999999], [6.9000000000000004, 3.1000000000000001, 5.0999999999999996, 2.2999999999999998], [5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999], [6.7999999999999998, 3.2000000000000002, 5.9000000000000004, 2.2999999999999998], [6.7000000000000002, 3.2999999999999998, 5.7000000000000002, 2.5], [6.7000000000000002, 3.0, 5.2000000000000002, 2.2999999999999998], [6.2999999999999998, 2.5, 5.0, 1.8999999999999999], [6.5, 3.0, 5.2000000000000002, 2.0], [6.2000000000000002, 3.3999999999999999, 5.4000000000000004, 2.2999999999999998], [5.9000000000000004, 3.0, 5.0999999999999996, 1.8]];
        $coeffs = [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -1.0, -0.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -1.0, -1.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -1.0, -1.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0], [1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]];
        $inters = [0.043376922607421875, 0.11445245146751404, -0.0031709671020507812];
        $classes = [0, 1, 2];

        // exp(-y|x-x'|^2)
        $kernels = array_fill(0, 150, 0);
        for ($i = 0; $i < 150; $i++) {
            $kernel = 0.;