Skip to content

Commit

Permalink
Updated constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Oct 17, 2023
1 parent 12613bb commit 965b51e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions examples/data_analysis_example/main.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module main

import vsl.ml
import vsl.plot
import vsl.ml { Data, Stat }
import vsl.plot { Axis, AxisTitle, Marker, Plot }

fn main() {
// Example data: two features (X1 and X2) and a label (y)
mut data := ml.Data.from_raw_xy([
mut data := Data.from_raw_xy([
[1.0, 2.0, 0.0],
[2.0, 3.0, 0.0],
[3.0, 3.0, 0.0],
Expand Down Expand Up @@ -62,7 +62,7 @@ fn main() {
])!

// Visualize data in a 3D scatter plot
mut plt_3d := plot.Plot.new()
mut plt_3d := Plot.new()

x1 := data.x.get_col(0)
x2 := data.x.get_col(1)
Expand Down Expand Up @@ -90,7 +90,7 @@ fn main() {
y: x2_class0
z: [][]f64{len: x1_class0.len, init: [0.0]}
mode: 'markers'
marker: plot.Marker{
marker: Marker{
size: []f64{len: x1_class0.len, init: 8.0}
color: []string{len: x1_class0.len, init: 'blue'}
}
Expand All @@ -101,7 +101,7 @@ fn main() {
y: x2_class1
z: [][]f64{len: x1_class1.len, init: [0.0]}
mode: 'markers'
marker: plot.Marker{
marker: Marker{
size: []f64{len: x1_class1.len, init: 8.0}
color: []string{len: x1_class1.len, init: 'red'}
}
Expand All @@ -111,13 +111,13 @@ fn main() {
// Configure the layout of the 3D plot
plt_3d.layout(
title: 'Two-class Data'
xaxis: plot.Axis{
title: plot.AxisTitle{
xaxis: Axis{
title: AxisTitle{
text: 'X1'
}
}
yaxis: plot.Axis{
title: plot.AxisTitle{
yaxis: Axis{
title: AxisTitle{
text: 'X2'
}
}
Expand All @@ -127,11 +127,11 @@ fn main() {
plt_3d.show()!

// Basic statistics analysis
mut stat := ml.Stats.from_data(mut data, 'Example Data')
mut stat := Stat.from_data(mut data, 'Example Data')
stat.update()

// Visualize statistics in a bar chart
mut plt_bars := plot.Plot.new()
mut plt_bars := Plot.new()

plt_bars.bar(
x: []string{len: stat.mean_x.len, init: 'Class ${index}'}
Expand Down
2 changes: 1 addition & 1 deletion ml/kmeans.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn Kmeans.new(mut data Data[f64], nb_classes int, name string) &Kmeans {
nb_members := []int{len: nb_classes}

// stat
mut stat := Stats.from_data(mut data, 'stat_${name}')
mut stat := Stat.from_data(mut data, 'stat_${name}')
stat.update()

// bins
Expand Down
2 changes: 1 addition & 1 deletion ml/linreg.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mut:
// data -- x,y data
// name -- unique name of this (observer) object
pub fn LinReg.new(mut data Data[f64], name string) &LinReg {
mut stat := Stats.from_data(mut data, 'stat_' + name)
mut stat := Stat.from_data(mut data, 'stat_' + name)
stat.update()
params := ParamsReg.new[f64](data.nb_features)
mut reg := &LinReg{
Expand Down
2 changes: 1 addition & 1 deletion ml/logreg.v~
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mut:
// params -- θ, b, λ
// name -- unique name of this (observer) object
pub fn LogReg.new(mut data Data, params &ParamsReg, name string) LogReg {
mut stat := Stats.from_data(mut data, "stat_" + name)
mut stat := Stat.from_data(mut data, "stat_" + name)
stat.update()
mut log_reg := LogReg{
name: name
Expand Down
2 changes: 1 addition & 1 deletion ml/workspace.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mut:
}

// stat returns a new Stat object
pub fn Stats.from_data[T](mut data Data[T], name string) &Stat[T] {
pub fn Stat.from_data[T](mut data Data[T], name string) &Stat[T] {
mut o := &Stat[T]{
name: name
data: data
Expand Down
2 changes: 1 addition & 1 deletion ml/workspace_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_stat_01() {
mut data := Data.from_raw_xy(xy)!

// stat
mut stat := Stats.from_data(mut data, 'stat')
mut stat := Stat.from_data(mut data, 'stat')

// notify update
data.notify_update()
Expand Down

0 comments on commit 965b51e

Please sign in to comment.