Commit 9f8b084e authored by Uwe Köckemann's avatar Uwe Köckemann
Browse files

Added new notebook for full example

parent 715f2406
......@@ -72,6 +72,7 @@
(didi-bin y [x] 0.5)
(balance y 0.1)
}
type:classification
alpha:1 ;; Parameter alpha
beta:1 ;; Parameter beta
))
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -23,6 +23,7 @@ class MovingTarget(ABC):
C = args[Symbolic("constraints")]
alpha = args[Symbolic("alpha")]
beta = args[Symbolic("beta")]
# initial step.
M = self.initialize_ext(d)
......
import importlib
import numpy as np
import sklearn
......@@ -12,8 +13,33 @@ from aiddl_core.parser.parser import parse_term
from aiddl_core.representation.symbolic import Symbolic
from aiddl_core.representation.integer import Integer
from aiddl_core.representation.list import List
from aiddl_core.representation.collection import Collection
from aiddl_core.function.function import Function
class SciKitLearnFunction(Function):
def __init__(self, cfg):
self.configure(cfg, None)
def configure(self, cfg, freg):
py_module = cfg[Symbolic("py_module")]
py_class = cfg[Symbolic("py_class")]
args = {}
for e in cfg:
if isinstance(e, Collection):
if e.get_key() != Symbolic("py_module") and e.get_key() != Symbolic("py_class"):
args[e.get_key().unpack()] = e.get_value().unpack()
m = importlib.import_module(str(py_module))
self.model = getattr(m, str(py_class))(**args)
def apply(self, mlProblem):
x, y = splitAiddlMlProblem(mlProblem)
self.model.fit(x, y)
y_p = self.model.predict(x)
r = []
for e in y_p:
r.append(parse_term(str(e)))
return List(r)
class RandomForestLearner(Function):
def __init__(self):
self.n_estimators = 50
......
from aiddl_core.parser.parser import parse_term
from aiddl_core.representation.key_value import KeyValue
from aiddl_core.representation.symbolic import Symbolic
from aiddl_core.representation.string import String
from aiddl_core.representation.integer import Integer
from aiddl_core.representation.tuple import Tuple
from aiddl_core.representation.list import List
from aiddl_core.representation.collection import Collection
from aiddl_core.function.function import Function
class CsvLoader(Function):
def apply(self, args):
fName = str(args[0].get_string_value())
sep = str(args[1].get_string_value())
label = str(args[2])
print("Separator: " + sep)
f = open(fName, "r")
lines = f.readlines()
f.close()
print(lines[0])
atts = []
for att in lines[0].split(sep):
if att.strip() != "":
print(att)
atts.append(Tuple([parse_term(att.strip()), Symbolic("org.aiddl.term")]))
data = []
for row in lines[1:]:
data_row = []
for e in row.split(sep):
if e.strip() != "":
data_row.append(parse_term(e.strip()))
data.append(List(data_row))
f.close()
return Tuple([
KeyValue(Symbolic("attributes"), List(atts)),
KeyValue(Symbolic("label"), label),
KeyValue(Symbolic("data"), List(data))])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment