Commit 710be4c6 authored by Steven Pisarski's avatar Steven Pisarski

Minor housekeeping

parent fd446c81
......@@ -159,8 +159,8 @@ object Generator extends App {
val labelMap = trainingSet.map(s => s._1.label -> s._2).collect().toMap
new NaiveBayesModel(fact, features, labelMap, definition.lambda)
case definition: LinearRegressionDefinition =>
new LinearRegressionModel(field = fact, trainingSet = features, numIterations = definition.iterations,
stepSize = definition.stepSize)
new LinearRegressionModel(fact, features, inputDef.algoWeights(fact), definition.iterations,
definition.stepSize)
}
case definition: ConstantDefinition =>
definition match {
......
......@@ -122,7 +122,8 @@ class InputDefinition(val temporal: Temporal, val dimensionSet: Set[Dimension],
/**
* Contains all fields where the key is the field's name
*/
val fieldMap = dimensionSet.map(d => d.name -> d).toMap ++ factSet.map(f => f.name -> f).toMap + (temporal.name -> temporal)
val fieldMap =
dimensionSet.map(d => d.name -> d).toMap ++ factSet.map(f => f.name -> f).toMap + (temporal.name -> temporal)
/**
* The Facts by name
......@@ -230,13 +231,12 @@ class InputDefinition(val temporal: Temporal, val dimensionSet: Set[Dimension],
* @param event - the event to parse
* @return - the feature set
*/
def temporalAlgoFeatures(event: Map[String, Any]): Seq[Double] = {
def temporalAlgoFeatures(event: Map[String, Any]): Seq[Double] =
temporal.algoDef match {
case algoDef:SupervisedTraining =>
algoFeatures(event, temporal.factPosition, algoDef)
case _ => Seq[Double]()
}
}
/**
* Return the training features for a given event and fact attribute by name
......@@ -244,13 +244,12 @@ class InputDefinition(val temporal: Temporal, val dimensionSet: Set[Dimension],
* @param fact - the fact field for which the training set will be generated
* @return - the features
*/
def factAlgoFeatures(event: Map[String, Any], fact: Fact): Seq[Double] = {
def factAlgoFeatures(event: Map[String, Any], fact: Fact): Seq[Double] =
fact.algoDef match {
case algoDef:SupervisedTraining =>
algoFeatures(event, fact.position, algoDef)
case _ => Seq[Double]()
}
}
/**
* Return the training features for a SupervisedTraining algorithm
......@@ -343,7 +342,6 @@ class InputDefinition(val temporal: Temporal, val dimensionSet: Set[Dimension],
if (factPosition < 0) !regression.omitFields.contains(p.name)
else p.position < factPosition && !regression.omitFields.contains(p.name))
.map(f => if (regression.weights.get(f.name) == None) 0d else regression.weights(f.name))
}
import com.fasterxml.jackson.annotation.JsonProperty
......@@ -359,9 +357,9 @@ class InputDefinitionYaml(@JsonProperty("temporal") temporal: TemporalFieldYaml,
require(temporal != null)
require(jDimensions != null && jDimensions.size() > 0)
require(jFacts != null && jFacts.size() > 0)
val inputDef = new InputDefinition(temporal.temporalField, jDimensions.asScala.map(f => f.dimField).toSet,
jFacts.asScala.map(f => f.factField).toSet)
val inputDef =
new InputDefinition(temporal.temporalField, jDimensions.asScala.map(f => f.dimField).toSet,
jFacts.asScala.map(f => f.factField).toSet)
}
/**
......@@ -377,8 +375,8 @@ class TemporalFieldYaml(@JsonProperty("name") name: String,
require(name != null)
require(fieldType != null && fieldType == "date") // Currently only supports type Date
if (fieldType == "date") require(dateFormat != null)
val temporalField = new DateTemporal(name, description, jDenormFields.asScala, algo.algorithm, dateFormat, factPosition)
val temporalField =
new DateTemporal(name, description, jDenormFields.asScala, algo.algorithm, dateFormat, factPosition)
}
/**
......@@ -393,8 +391,7 @@ class DimensionFieldYaml(@JsonProperty("name") name: String,
require(fieldType != null &&
(fieldType == "integer" || fieldType == "float" || fieldType == "string" || fieldType == "date"))
if (fieldType == "date") require(dateFormat != null)
val dimField: Dimension = fieldType match {
val dimField = fieldType match {
case "date" => new DateDimension(name, description, position, dateFormat)
case "string" => new StringDimension(name, description, position)
case "integer" => new IntDimension(name, description, position)
......@@ -417,7 +414,7 @@ class FactFieldYaml(@JsonProperty("name") name: String,
(fieldType == "integer" || fieldType == "float" || fieldType == "string" || fieldType == "date"))
if (fieldType == "date") require(dateFormat != null)
val factField: Fact = fieldType match {
val factField = fieldType match {
case "date" => new DateFact(name, description, position, algo.algorithm, dateFormat)
case "string" => new StringFact(name, description, position, algo.algorithm)
case "integer" => new IntFact(name, description, position, algo.algorithm)
......
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