GitHub PullRequestReviewCommentEvent at 2014-05-10 11:27:32
Repository: golearn
Actor: Sentimentron
Payload: {"comment":{"url":"https://api.github.com/repos/sjwhitworth/golearn/pulls/comments/12503747","id":12503747,"diff_hunk":"@@ -0,0 +1,271 @@\n+package base\n+\n+import \"fmt\"\n+import \"strconv\"\n+\n+const (\n+\t// CategoricalType is for Attributes which represent values distinctly.\n+\tCategoricalType = iota\n+\t// Float64Type should be replaced with a FractionalNumeric type [DEPRECATED].\n+\tFloat64Type\n+)\n+\n+// Attribute Attributes disambiguate columns of the feature matrix and declare their types.\n+type Attribute interface {\n+\t// Returns the general characterstics of this Attribute .\n+\t// to avoid the overhead of casting\n+\tGetType() int\n+\t// Returns the human-readable name of this Attribute.\n+\tGetName() string\n+\t// Sets the human-readable name of this Attribute.\n+\tSetName(string)\n+\t// Gets a human-readable overview of this Attribute for debugging.\n+\tString() string\n+\t// Converts an int value to a string representation of that int's\n+\t// value under this Attribute's encoding scheme.\n+\t// For example:\n+\t//  For a FloatAttribute: 4 might give back \"4.00\"\n+\t//  For a CategoricalAttribute with values [\"iris-setosa\", \"iris-viriginica\"]:\n+\t//   1 might give back \"iris-virginica\".\n+\tIntValToString(int) string\n+\t// Converts a value given from a human-readable string into a system\n+\t// representation. For example, a CategoricalAttribute with values\n+\t// [\"iris-setosa\", \"iris-virginica\"] would return the float64\n+\t// representation of 0 when given \"iris-setosa\".\n+\tGetSysValFromString(string) float64\n+\t// Converts a given value from a system representation into a human\n+\t// representation. For example, a CategoricalAttribute with values\n+\t// [\"iris-setosa\", \"iris-viriginica\"] might return \"iris-setosa\"\n+\t// when given 0.0 as the argument.\n+\tSysValToString(float64) string\n+\t// Tests for equality with another Attribute. Other Attributes are\n+\t// considered equal if:\n+\t// * They have the same type (i.e. FloatAttribute <> CategoricalAttribute)\n+\t// * They have the same name\n+\t// * If applicable, they have the same categorical values (though not\n+\t//   necessarily in the same order).\n+\tEquals(Attribute) bool\n+}\n+\n+// FloatAttribute is an implementation which stores floating point\n+// representations of numbers.\n+type FloatAttribute struct {\n+\tName string\n+}\n+\n+// Equals tests a FloatAttribute for equality with another Attribute.\n+//\n+// Returns false if the other Attribute has a different name\n+// or if the other Attribute is not a FloatAttribute.\n+func (Attr *FloatAttribute) Equals(other Attribute) bool {\n+\t// Check whether this FloatAttribute is equal to another\n+\t_, ok := other.(*FloatAttribute)\n+\tif !ok {\n+\t\t// Not the same type, so can't be equal\n+\t\treturn false\n+\t}\n+\tif Attr.GetName() != other.GetName() {\n+\t\treturn false\n+\t}\n+\treturn true\n+}\n+\n+// GetName returns this FloatAttribute's human-readable name.\n+func (Attr *FloatAttribute) GetName() string {\n+\treturn Attr.Name\n+}\n+\n+// SetName sets this FloatAttribute's human-readable name.\n+func (Attr *FloatAttribute) SetName(name string) {\n+\tAttr.Name = name\n+}\n+\n+// GetType returns Float64Type.\n+func (Attr *FloatAttribute) GetType() int {\n+\treturn Float64Type\n+}\n+\n+// String returns a human-readable summary of this Attribute.\n+// e.g. \"FloatAttribute(Sepal Width)\"\n+func (Attr *FloatAttribute) String() string {\n+\treturn fmt.Sprintf(\"FloatAttribute(%s)\", Attr.Name)\n+}\n+\n+// GetSysValFromString parses the given rawVal string to a float64 and returns it.\n+//\n+// float64 happens to be a 1-to-1 mapping to the system representation.\n+func (Attr *FloatAttribute) GetSysValFromString(rawVal string) float64 {\n+\tf, err := strconv.ParseFloat(rawVal, 64)\n+\tif err != nil {\n+\t\tpanic(err)\n+\t}\n+\treturn f\n+}\n+\n+// IntValToString converts the given integer rawVal to string via the system\n+// representation.\n+func (Attr *FloatAttribute) IntValToString(rawVal int) string {\n+\treturn Attr.SysValToString(float64(rawVal))\n+}\n+\n+// SysValToString converts a given system value to to a string with two decimal\n+// places of precision [TODO: revise this and allow more precision].\n+func (Attr *FloatAttribute) SysValToString(rawVal float64) string {\n+\treturn fmt.Sprintf(\"%.2f\", rawVal)\n+}\n+\n+// GetSysVal returns the system representation of userVal.\n+//\n+// Because FloatAttribute represents float64 types, this\n+// just returns its argument.\n+func (Attr *FloatAttribute) GetSysVal(userVal float64) float64 {\n+\treturn userVal\n+}\n+\n+// GetUsrVal returns the user representation of sysVal.\n+//\n+// Because FloatAttribute represents float64 types, this\n+// just returns its argument.\n+func (Attr *FloatAttribute) GetUsrVal(sysVal float64) float64 {\n+\treturn sysVal\n+}\n+\n+// CategoricalAttribute is an Attribute implementation\n+// which stores discrete string values\n+// - useful for representing classes.\n+type CategoricalAttribute struct {\n+\tName   string\n+\tValues []string\n+}\n+\n+// GetName returns the human-readable name assigned to this attribute.\n+func (Attr *CategoricalAttribute) GetName() string {\n+\treturn Attr.Name\n+}\n+\n+// SetName sets the human-readable name on this attribute.\n+func (Attr *CategoricalAttribute) SetName(name string) {\n+\tAttr.Name = name\n+}\n+\n+// GetType returns CategoricalType to avoid casting overhead.\n+func (Attr *CategoricalAttribute) GetType() int {\n+\treturn CategoricalType\n+}\n+\n+// GetSysVal returns the system representation of userVal as an index into the Values slice\n+// If the userVal can't be found, it returns -1.\n+func (Attr *CategoricalAttribute) GetSysVal(userVal string) float64 {","path":"base/attributes.go","position":158,"original_position":158,"commit_id":"aeec3a66865463fb29639de67edbc2ab252aedb0","original_commit_id":"aeec3a66865463fb29639de67edbc2ab252aedb0","user":{"login":"Sentimentron","id":3706681,"avatar_url":"https://avatars.githubusercontent.com/u/3706681?","gravatar_id":"5de1d04e8e3068c534461ef53b4572c0","url":"https://api.github.com/users/Sentimentron","html_url":"https://github.com/Sentimentron","followers_url":"https://api.github.com/users/Sentimentron/followers","following_url":"https://api.github.com/users/Sentimentron/following{/other_user}","gists_url":"https://api.github.com/users/Sentimentron/gists{/gist_id}","starred_url":"https://api.github.com/users/Sentimentron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sentimentron/subscriptions","organizations_url":"https://api.github.com/users/Sentimentron/orgs","repos_url":"https://api.github.com/users/Sentimentron/repos","events_url":"https://api.github.com/users/Sentimentron/events{/privacy}","received_events_url":"https://api.github.com/users/Sentimentron/received_events","type":"User","site_admin":false},"body":"For concurrency purposes, it may be appropriate to add a flag indicating that this *Attribute* after reading isn't modifiable and that *GetSysValFromString* should panic() in that circumstance if it encounters a new value. That said, the way it's set up at the moment is *GetSysValFromString* is a \"safe\" operation, meaning that it can't invalidate the data already assigned.","created_at":"2014-05-10T11:27:32Z","updated_at":"2014-05-10T11:27:32Z","html_url":"https://github.com/sjwhitworth/golearn/pull/27#discussion_r12503747","pull_request_url":"https://api.github.com/repos/sjwhitworth/golearn/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/sjwhitworth/golearn/pulls/comments/12503747"},"html":{"href":"https://github.com/sjwhitworth/golearn/pull/27#discussion_r12503747"},"pull_request":{"href":"https://api.github.com/repos/sjwhitworth/golearn/pulls/27"}}}}