target variance for each solver run. authored by Yosh
This commit is contained in:
parent
6ebe33a76b
commit
1f00e1e1bc
@ -1,5 +1,14 @@
|
|||||||
|
|
||||||
def boolean_to_int(value: bool) -> int:
|
def boolean_to_int(value: bool) -> int:
|
||||||
if value:
|
if value:
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def is_float(element: str) -> bool:
|
||||||
|
try:
|
||||||
|
float(element)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
@ -3,7 +3,9 @@ import io
|
|||||||
import re
|
import re
|
||||||
from tokenize import String
|
from tokenize import String
|
||||||
|
|
||||||
|
from helpers import common_helper
|
||||||
from models.item import Item
|
from models.item import Item
|
||||||
|
from models.solver_run import SolverRun
|
||||||
|
|
||||||
def csv_to_item(items_csv_reader, solver_run):
|
def csv_to_item(items_csv_reader, solver_run):
|
||||||
items = []
|
items = []
|
||||||
@ -17,7 +19,7 @@ def csv_to_item(items_csv_reader, solver_run):
|
|||||||
item = {'attributes': []}
|
item = {'attributes': []}
|
||||||
|
|
||||||
# ensure that the b param is formatted correctly
|
# ensure that the b param is formatted correctly
|
||||||
if row[len(headers) - 1] != '' and is_float(row[len(headers) - 1]):
|
if row[len(headers) - 1] != '' and common_helper.is_float(row[len(headers) - 1]):
|
||||||
for key, col in enumerate(headers):
|
for key, col in enumerate(headers):
|
||||||
if solver_run.irt_model.formatted_b_param() == col:
|
if solver_run.irt_model.formatted_b_param() == col:
|
||||||
value = float(row[key])
|
value = float(row[key])
|
||||||
@ -100,11 +102,14 @@ def key_to_uuid(key):
|
|||||||
return re.split("_", key)[0]
|
return re.split("_", key)[0]
|
||||||
|
|
||||||
|
|
||||||
def solution_items(variables, solver_run):
|
def solution_items(variables: list, solver_run: SolverRun) -> (list, list):
|
||||||
form_items = []
|
form_items = []
|
||||||
|
solver_variables = []
|
||||||
|
|
||||||
for v in variables:
|
for v in variables:
|
||||||
if v.varValue > 0:
|
if v.varValue > 0:
|
||||||
|
solver_variables.append(v.name)
|
||||||
|
|
||||||
if 'Item_' in v.name:
|
if 'Item_' in v.name:
|
||||||
item_id = v.name.replace('Item_', '')
|
item_id = v.name.replace('Item_', '')
|
||||||
item = solver_run.get_item(int(item_id))
|
item = solver_run.get_item(int(item_id))
|
||||||
@ -118,17 +123,9 @@ def solution_items(variables, solver_run):
|
|||||||
for item in bundle.items:
|
for item in bundle.items:
|
||||||
if item: form_items.append(item)
|
if item: form_items.append(item)
|
||||||
|
|
||||||
return form_items
|
return form_items, solver_variables
|
||||||
|
|
||||||
def print_problem_variables(problem):
|
def print_problem_variables(problem):
|
||||||
# Uncomment this as needed in local dev
|
# Uncomment this as needed in local dev
|
||||||
# print(problem);
|
# print(problem);
|
||||||
for v in problem.variables(): print(v.name, "=", v.varValue);
|
for v in problem.variables(): print(v.name, "=", v.varValue)
|
||||||
|
|
||||||
# probably a better place for this...
|
|
||||||
def is_float(element: String) -> bool:
|
|
||||||
try:
|
|
||||||
float(element)
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import List
|
from typing import List, TypeVar, Type
|
||||||
|
|
||||||
from helpers import irt_helper
|
from helpers import irt_helper
|
||||||
|
|
||||||
|
from models.solver_run import SolverRun
|
||||||
from models.item import Item
|
from models.item import Item
|
||||||
from models.target import Target
|
from models.target import Target
|
||||||
|
|
||||||
from lib.irt.test_response_function import TestResponseFunction
|
from lib.irt.test_response_function import TestResponseFunction
|
||||||
|
|
||||||
|
_T = TypeVar("_T")
|
||||||
|
|
||||||
class Form(BaseModel):
|
class Form(BaseModel):
|
||||||
items: List[Item]
|
items: List[Item]
|
||||||
@ -15,13 +17,15 @@ class Form(BaseModel):
|
|||||||
tif_results: List[Target]
|
tif_results: List[Target]
|
||||||
tcc_results: List[Target]
|
tcc_results: List[Target]
|
||||||
status: str = 'Not Optimized'
|
status: str = 'Not Optimized'
|
||||||
|
solver_variables: List[str]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, items, solver_run, status):
|
def create(cls: Type[_T], items: list, solver_run: SolverRun, status: str, solver_variables: list) -> _T:
|
||||||
return cls(
|
return cls(
|
||||||
items=items,
|
items=items,
|
||||||
cut_score=TestResponseFunction(solver_run.irt_model).calculate(
|
cut_score=TestResponseFunction(solver_run.irt_model).calculate(
|
||||||
items, theta=solver_run.theta_cut_score),
|
items, theta=solver_run.theta_cut_score),
|
||||||
tif_results=irt_helper.generate_tif_results(items, solver_run),
|
tif_results=irt_helper.generate_tif_results(items, solver_run),
|
||||||
tcc_results=irt_helper.generate_tcc_results(items, solver_run),
|
tcc_results=irt_helper.generate_tcc_results(items, solver_run),
|
||||||
status=status)
|
status=status,
|
||||||
|
solver_variables=solver_variables)
|
||||||
|
@ -10,6 +10,7 @@ class ObjectiveFunction(BaseModel):
|
|||||||
# likely with models representing each objective function type
|
# likely with models representing each objective function type
|
||||||
tif_targets: List[Target]
|
tif_targets: List[Target]
|
||||||
tcc_targets: List[Target]
|
tcc_targets: List[Target]
|
||||||
|
target_variance_percentage: int = 10
|
||||||
objective: AnyStr = "minimize"
|
objective: AnyStr = "minimize"
|
||||||
weight: Dict = {'tif': 1, 'tcc': 1}
|
weight: Dict = {'tif': 1, 'tcc': 1}
|
||||||
|
|
||||||
|
@ -105,6 +105,15 @@ class LoftService(Base):
|
|||||||
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
# Dynamic constraints.. currently we only support Metadata and Bundles(Cases/Passages)
|
||||||
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
problem = solver_helper.build_constraints(self.solver_run, problem, items, bundles)
|
||||||
|
|
||||||
|
# form uniqueness constraints
|
||||||
|
for form in solution.forms:
|
||||||
|
form_item_options = [
|
||||||
|
bundles[bundle.id] for bundle in self.solver_run.bundles
|
||||||
|
] + [
|
||||||
|
items[item.id] for item in self.solver_run.unbundled_items()
|
||||||
|
]
|
||||||
|
problem += len(set(form.solver_variables)&set(form_item_options)) / float(len(set(form.solver_variables) | set(form_item_options))) * 100 >= 10
|
||||||
|
|
||||||
logging.info('Creating TIF and TCC Elastic constraints')
|
logging.info('Creating TIF and TCC Elastic constraints')
|
||||||
|
|
||||||
# Behold our very own Elastic constraints!
|
# Behold our very own Elastic constraints!
|
||||||
@ -181,10 +190,10 @@ class LoftService(Base):
|
|||||||
|
|
||||||
return solution
|
return solution
|
||||||
|
|
||||||
def add_form_to_solution(self, problem, solution):
|
def add_form_to_solution(self, problem: LpProblem, solution: Solution):
|
||||||
# add return items and create as a form
|
# add return items and create as a form
|
||||||
form_items = service_helper.solution_items(problem.variables(), self.solver_run)
|
form_items, solver_variables = service_helper.solution_items(problem.variables(), self.solver_run)
|
||||||
form = Form.create(form_items, self.solver_run, LpStatus[problem.status])
|
form = Form.create(form_items, self.solver_run, LpStatus[problem.status], solver_variables)
|
||||||
|
|
||||||
solution.forms.append(form)
|
solution.forms.append(form)
|
||||||
|
|
||||||
|
@ -19,6 +19,14 @@ class SolverSandbox:
|
|||||||
if ApplicationConfigs.local_dev_env:
|
if ApplicationConfigs.local_dev_env:
|
||||||
body = {'Records': [{'eventVersion': '2.1', 'eventSource': 'aws:s3', 'awsRegion': 'us-east-1', 'eventTime': '2022-03-17T13:51:22.708Z', 'eventName': 'ObjectCreated:Put', 'userIdentity': {'principalId': 'AIDAJDPLRKLG7UEXAMPLE'}, 'requestParameters': {'sourceIPAddress': '127.0.0.1'}, 'responseElements': {'x-amz-request-id': '25ecd478', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2'}, 's3': {'s3SchemaVersion': '1.0', 'configurationId': 'testConfigRule', 'bucket': {'name': 'measure-local-solver-ingest', 'ownerIdentity': {'principalId': 'A3NL1KOZZKExample'}, 'arn': 'arn:aws:s3:::measure-local-solver-ingest'}, 'object': {'key': '40f23de0-8827-013a-a353-0242ac120010_solver_run.tar.gz', 'size': 491, 'eTag': '"2b423d91e80d931302192e781b6bd47c"', 'versionId': None, 'sequencer': '0055AED6DCD90281E5'}}}]}
|
body = {'Records': [{'eventVersion': '2.1', 'eventSource': 'aws:s3', 'awsRegion': 'us-east-1', 'eventTime': '2022-03-17T13:51:22.708Z', 'eventName': 'ObjectCreated:Put', 'userIdentity': {'principalId': 'AIDAJDPLRKLG7UEXAMPLE'}, 'requestParameters': {'sourceIPAddress': '127.0.0.1'}, 'responseElements': {'x-amz-request-id': '25ecd478', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2'}, 's3': {'s3SchemaVersion': '1.0', 'configurationId': 'testConfigRule', 'bucket': {'name': 'measure-local-solver-ingest', 'ownerIdentity': {'principalId': 'A3NL1KOZZKExample'}, 'arn': 'arn:aws:s3:::measure-local-solver-ingest'}, 'object': {'key': '40f23de0-8827-013a-a353-0242ac120010_solver_run.tar.gz', 'size': 491, 'eTag': '"2b423d91e80d931302192e781b6bd47c"', 'versionId': None, 'sequencer': '0055AED6DCD90281E5'}}}]}
|
||||||
|
|
||||||
|
# CPNRE item bank with metadata and cases
|
||||||
|
# body = {'Records': [{'eventVersion': '2.1', 'eventSource': 'aws:s3', 'awsRegion': 'us-east-1', 'eventTime': '2022-03-23T18:49:42.979Z', 'eventName': 'ObjectCreated:Put', 'userIdentity': {'principalId': 'AIDAJDPLRKLG7UEXAMPLE'}, 'requestParameters': {'sourceIPAddress': '127.0.0.1'}, 'responseElements': {'x-amz-request-id': 'c4efd257', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2'}, 's3': {'s3SchemaVersion': '1.0', 'configurationId': 'testConfigRule', 'bucket': {'name': 'measure-local-solver-ingest', 'ownerIdentity': {'principalId': 'A3NL1KOZZKExample'}, 'arn': 'arn:aws:s3:::measure-local-solver-ingest'}, 'object': {'key': 'e8f38480-8d07-013a-5ee6-0242ac120010_solver_run.tar.gz', 'size': 12716, 'eTag': '"94189c36aef04dde3babb462442c3af3"', 'versionId': None, 'sequencer': '0055AED6DCD90281E5'}}}]}
|
||||||
|
|
||||||
|
# LOFT item bank with metadata and cases
|
||||||
|
body = {'Records': [{'eventVersion': '2.1', 'eventSource': 'aws:s3', 'awsRegion': 'us-east-1', 'eventTime': '2022-03-22T19:36:53.568Z', 'eventName': 'ObjectCreated:Put', 'userIdentity': {'principalId': 'AIDAJDPLRKLG7UEXAMPLE'}, 'requestParameters': {'sourceIPAddress': '127.0.0.1'}, 'responseElements': {'x-amz-request-id': '61f320d0', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2'}, 's3': {'s3SchemaVersion': '1.0', 'configurationId': 'testConfigRule', 'bucket': {'name': 'measure-local-solver-ingest', 'ownerIdentity': {'principalId': 'A3NL1KOZZKExample'}, 'arn': 'arn:aws:s3:::measure-local-solver-ingest'}, 'object': {'key': '5971f500-8c45-013a-5d13-0242ac120010_solver_run.tar.gz', 'size': 619, 'eTag': '"a3cbba098e9f6a445cba6014e47ccaf9"', 'versionId': None, 'sequencer': '0055AED6DCD90281E5'}}}]}
|
||||||
|
|
||||||
|
# Latest CPNRE Item Bank with metadata and cases
|
||||||
|
body = {'Records': [{'eventVersion': '2.1', 'eventSource': 'aws:s3', 'awsRegion': 'us-east-1', 'eventTime': '2022-03-24T15:47:54.652Z', 'eventName': 'ObjectCreated:Put', 'userIdentity': {'principalId': 'AIDAJDPLRKLG7UEXAMPLE'}, 'requestParameters': {'sourceIPAddress': '127.0.0.1'}, 'responseElements': {'x-amz-request-id': '1969b1ed', 'x-amz-id-2': 'eftixk72aD6Ap51TnqcoF8eFidJG9Z/2'}, 's3': {'s3SchemaVersion': '1.0', 'configurationId': 'testConfigRule', 'bucket': {'name': 'measure-local-solver-ingest', 'ownerIdentity': {'principalId': 'A3NL1KOZZKExample'}, 'arn': 'arn:aws:s3:::measure-local-solver-ingest'}, 'object': {'key': 'ab40ca20-8db7-013a-a88f-0242ac120013_solver_run.tar.gz', 'size': 24111, 'eTag': '"718a1a17b5dd5219b8e179bfd1ddf1ca"', 'versionId': None, 'sequencer': '0055AED6DCD90281E5'}}}]}
|
||||||
LoftService(body).process()
|
LoftService(body).process()
|
||||||
|
|
||||||
def yosh_loop():
|
def yosh_loop():
|
||||||
@ -94,7 +102,6 @@ class SolverSandbox:
|
|||||||
}
|
}
|
||||||
|
|
||||||
items = LpVariable.dicts('Item', Items, cat='Binary')
|
items = LpVariable.dicts('Item', Items, cat='Binary')
|
||||||
|
|
||||||
drift = 0
|
drift = 0
|
||||||
max_drift = 25# 25% elasticity
|
max_drift = 25# 25% elasticity
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user