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

Cleaning up

parent c6425cc0
......@@ -157,8 +157,8 @@
"output_type": "stream",
"text": [
"DIDI (pre-learning): 1.3178840744255598\n",
"DIDI (post-learning): 1.23095753493759\n",
"ACC (test data): 0.8536383225592574\n"
"DIDI (post-learning): 1.162334319282314\n",
"ACC (test data): 0.8519807724183657\n"
]
}
],
......@@ -281,7 +281,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"scrolled": true
},
......@@ -290,47 +290,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"False\n",
"Constraint added: FairnessConstraint: didi <= 0.01\n",
"Constraint satisfaction: False\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n",
"Constraint satisfaction: True\n",
"Solving\n"
"Constraint satisfaction: False\n"
]
}
],
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
from abc import ABC, abstractmethod
from aiddl_core.representation.symbolic import Symbolic
from aiddl_core.representation.integer import Integer
from aiddl_core.representation.infinity import Infinity
from aiddl_core.representation.tuple import Tuple
from aiddl_core.container.container import Container
import aiddl_core.function.default as dfun
from aiddl_core.tools.logger import Logger
import aiddl_core.parser.parser as parser
from aiddl_network.grpc_function import GrpcFunction
from aiddl_network.aiddl_grpc_server import AiddlServicer
from aiddl_network.aiddl_grpc_server import LOADER_URI
# from moving_target_cplex import MovingTargetRegCplex, MovingTargetClsCplex
# from moving_target_smt import MovingTargetRegSMT
from utils import get_problem
# Loaded modules (aka AIDDL files) go to container:
C = Container()
# Loaded functions (#def in modules, or MovingTargetCplex instance)
# go to function registry:
F = dfun.get_default_function_registry(C)
# Load example (returns URI of module)
# example_module_uri = parser.parse("../../aiddl/example-01.aiddl", C, F)
example_module_uri = parser.parse("../../aiddl/example-fair-reg.aiddl", C, F)
# Fetch "examples" entry from module:
example_entry = C.get_entry(Symbolic("examples"), module=example_module_uri)
# Take value of entry:
example_data = example_entry.get_value()
# NOTE: The following part relies on org.aiddl.network which I still need to publish...
# Connection to AIDDL GrpcServer
host = "localhost"
port = 8011
# Create function that can create functions on server
f_create = GrpcFunction(host,
port,
Symbolic("org.aiddl.eval.load-function"))
# Data neeed to create learner through f_create
dt_learner_conf = parser.parse_term('''
(
name:ID3
module:my
class:org.aiddl.common.learning.decision_tree.ID3
config:{}
)
''')
ls_expansion = parser.parse_term('''
(
name:Expansion
module:my
class:org.aiddl.common.learning.linear_regression.ExpansionFunction
config:{}
)
''')
f_create.apply(ls_expansion)
ls_learner_conf = parser.parse_term('''
(
name:LeastSquares
module:my
class:org.aiddl.common.learning.linear_regression.LinearRegression
config:{ expansion:^my.Expansion }
)
''')
lap_cfg = parser.parse_term('''
(
name:LearnAndApplyFunction
module:my
class:org.aiddl.common.learning.supervised.LearnAndApplyFunction
config:{ learner:^my.LeastSquares }
)
''')
# Create function on server
dt_learner_uri = f_create.apply(dt_learner_conf)
# Create local proxy to newly created function
f_ID3 = GrpcFunction(host, port, dt_learner_uri)
# Create function on server
mse_learner_uri = f_create.apply(ls_learner_conf)
# Create local proxy to newly created function
f_MSE = GrpcFunction(host, port, mse_learner_uri)
# Create function on server
lap_uri = f_create.apply(lap_cfg)
# Create local proxy to newly created function
f_LAP = GrpcFunction(host, port, lap_uri)
# Finally, we can apply mean square error to data:
# weights = f_MSE.apply(example_data)
# print("Weights:", weights)
# y_k = f_LAP.apply(example_data)
# print("Result:", y_k)
# Create local function to expand data and
# hook it into least squares function running on server
# class ExpandData:
# def apply(self, x):
# return Tuple([Integer(1), x])
# F.add_function(ExpandData(), Symbolic("my.expander"))
mt_data = C.get_entry(Symbolic("moving-targets-problem"), module=example_module_uri).get_value()
mt_data = mt_data.resolve(C)
# mtc = MovingTargetRegCplex(f_LAP, n=30)
# mtc = MovingTargetClsCplex(f_LAP, n=10)
# mtc = MovingTargetRegSMT(f_LAP, n=5)
# Take value of entry:
problem_type = mt_data[Symbolic("type")].string_value()
movt_class = get_problem(problem_type, solver='smt')
mtc = movt_class(f_LAP, n=5)
# print(Logger.pretty_print(mt_data, 0))
mtc.apply(mt_data)
from abc import ABC, abstractmethod
from aiddl_core.representation.symbolic import Symbolic
from aiddl_core.representation.integer import Integer
from aiddl_core.representation.infinity import Infinity
from aiddl_core.representation.tuple import Tuple
from aiddl_core.container.container import Container
import aiddl_core.function.default as dfun
from aiddl_core.tools.logger import Logger
import aiddl_core.parser.parser as parser
from aiddl_network.grpc_function import GrpcFunction
from aiddl_network.aiddl_grpc_server import AiddlServicer
from aiddl_network.aiddl_grpc_server import LOADER_URI
from preprocessing import OneHotEncoder
# Loaded modules (aka AIDDL files) go to container:
C = Container()
# Loaded functions (#def in modules, or MovingTargetCplex instance)
# go to function registry:
F = dfun.get_default_function_registry(C)
# Load example (returns URI of module)
example_module_uri = parser.parse("../../aiddl/encoding-test.aiddl", C, F)
# Fetch "examples" entry from module:
example_entry = C.get_entry(Symbolic("enc-test-01"), module=example_module_uri)
# Take value of entry:
example_data = example_entry.get_value()
encoder = OneHotEncoder()
print(Logger.pretty_print(example_data, 0))
encoded_prob = encoder.apply(example_data)
print(Logger.pretty_print(encoded_prob, 0))
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