Ejemplo n.º 1
0
func (problem *Problem) Add(trainInst TrainingInstance) {
	features := sortedFeatureVector(trainInst.Features)

	nodes := C.nodes_new(C.size_t(len(features)))

	for idx, val := range features {
		C.nodes_put(nodes, C.size_t(idx), C.int(val.Index), C.double(val.Value))
	}

	C.problem_add_train_inst(problem.problem, nodes, C.double(trainInst.Label))
}
Ejemplo n.º 2
0
// Add adds a training instance to the problem.
func (problem *Problem) Add(trainInst TrainingInstance) error {
	if err := verifyFeatureIndices(trainInst.Features); err != nil {
		return err
	}

	features := sortedFeatureVector(trainInst.Features)

	nodes := newNodes(C.size_t(len(features)))
	problem.insts = append(problem.insts, nodes)

	for idx, val := range features {
		C.nodes_put(nodes, C.size_t(idx), C.int(val.Index), C.double(val.Value))
	}

	C.problem_add_train_inst(problem.problem, nodes, C.double(trainInst.Label))

	return nil
}