Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Bab01/A/1204010/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Kelas A

## certi
![image]![image](https://user-images.githubusercontent.com/94116594/231246242-59ba503a-74e1-4747-8955-9bc5c7e2a917.png)
26 changes: 26 additions & 0 deletions Chapter01/A/1204010/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/JPratama7/ai

go 1.20

require (
github.com/apache/arrow/go/arrow v0.0.0-20210105145422-88aaea5262db // indirect
github.com/awalterschulze/gographviz v0.0.0-20190221210632-1e9ccb565bca // indirect
github.com/chewxy/hm v1.0.0 // indirect
github.com/chewxy/math32 v1.0.7-0.20210223031236-a3549c8cb6a9 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/flatbuffers v1.12.0 // indirect
github.com/leesper/go_rng v0.0.0-20171009123644-5344a9259b21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xtgo/set v1.0.0 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gonum.org/v1/gonum v0.8.2 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gorgonia.org/cu v0.9.3 // indirect
gorgonia.org/dawson v1.2.0 // indirect
gorgonia.org/gorgonia v0.9.17 // indirect
gorgonia.org/tensor v0.9.17 // indirect
gorgonia.org/vecf32 v0.9.0 // indirect
gorgonia.org/vecf64 v0.9.0 // indirect
)
201 changes: 201 additions & 0 deletions Chapter01/A/1204010/go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Chapter01/A/1204010/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
34 changes: 34 additions & 0 deletions Chapter01/A/1204010/polynomial.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"

"gorgonia.org/gorgonia"
)

func main() {
g := gorgonia.NewGraph()

// Define input tensor
x := gorgonia.NewScalar(g, gorgonia.Float64, gorgonia.WithName("x"))
z := gorgonia.NewScalar(g, gorgonia.Float64, gorgonia.WithName("z"))

// Define output tensor using polynomial function
y := gorgonia.Must(gorgonia.Add(gorgonia.Must(gorgonia.Mul(x, x)), gorgonia.Must(gorgonia.Mul(x, z))))

// Create a VM to run the graph
machine := gorgonia.NewTapeMachine(g)
defer machine.Close()

gorgonia.Let(x, 4.0)
gorgonia.Let(z, 10.0)

// Run the graph with input value 2.0
if err := machine.RunAll(); err != nil {
fmt.Println(err)
return
}

// Print the output value
fmt.Printf("\nHasil : %+v\n", y.Value())
}
36 changes: 36 additions & 0 deletions Chapter01/A/1204010/tutorialAdd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"fmt"
"log"

. "gorgonia.org/gorgonia"
)

func main() {
g := NewGraph()

var x, y, z *Node
var err error

// define the expression
x = NewScalar(g, Float64, WithName("x"))
y = NewScalar(g, Float64, WithName("y"))
z, err = Add(x, y)
if err != nil {
log.Fatal(err)
}

// create a VM to run the program on
machine := NewTapeMachine(g)

// set initial values then run
Let(x, 4.0)
Let(y, 2.5)
if machine.RunAll() != nil {
log.Fatal(err)
}

fmt.Printf("%v", z.Value())
// Output: 4.5
}
46 changes: 46 additions & 0 deletions Chapter01/A/1204010/tutorialMatrix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"log"

G "gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)

func main() {
g := G.NewGraph()

matB := []float32{0.9,0.7,0.4,0.2}
matT := tensor.New(tensor.WithBacking(matB), tensor.WithShape(2, 2))
mat := G.NewMatrix(g,
tensor.Float32,
G.WithName("W"),
G.WithShape(2, 2),
G.WithValue(matT),
)

vecB := []float32{5,7}
vecT := tensor.New(tensor.WithBacking(vecB), tensor.WithShape(2))

vec := G.NewVector(g,
tensor.Float32,
G.WithName("x"),
G.WithShape(2),
G.WithValue(vecT),
)

z, err := G.Mul(mat, vec)

// create a VM to run the program on
machine := G.NewTapeMachine(g)

// set initial values then run

if machine.RunAll() != nil {
log.Fatal(err)
}

fmt.Println(z.Value().Data())
// Output: [9.4 3.4]
}
59 changes: 59 additions & 0 deletions Chapter01/A/1204010/tutorialWxB.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"fmt"
"io/ioutil"
"log"

G "gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)

func main() {
g := G.NewGraph()

matB := []float64{0.9, 0.7, 0.4, 0.2}
matT := tensor.New(tensor.WithBacking(matB), tensor.WithShape(2, 2))
mat := G.NewMatrix(g,
tensor.Float64,
G.WithName("W"),
G.WithShape(2, 2),
G.WithValue(matT),
)

vecB := []float64{5, 7}
vecT := tensor.New(tensor.WithBacking(vecB), tensor.WithShape(2))

vec := G.NewVector(g,
tensor.Float64,
G.WithName("x"),
G.WithShape(2),
G.WithValue(vecT),
)

b := G.NewScalar(g, tensor.Float64, G.WithName("b"), G.WithValue(3.0))

a, err := G.Mul(mat, vec)
if err != nil {
log.Fatal(err)
}

z, err := G.Add(a, b)
if err != nil {
log.Fatal(err)
}

// create a VM to run the program on
machine := G.NewTapeMachine(g)

// set initial values then run

if machine.RunAll() != nil {
log.Fatal(err)
}

fmt.Println(z.Value().Data())
// Output: [12.399999999999999 6.4]

ioutil.WriteFile("simple_graph.dot", []byte(g.ToDot()), 0644)
}
26 changes: 26 additions & 0 deletions Chapter02/A/1204010/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/hanandestiarin/ai/tree/master/Chapter01/A

go 1.20

require (
github.com/apache/arrow/go/arrow v0.0.0-20210105145422-88aaea5262db // indirect
github.com/awalterschulze/gographviz v0.0.0-20190221210632-1e9ccb565bca // indirect
github.com/chewxy/hm v1.0.0 // indirect
github.com/chewxy/math32 v1.0.7-0.20210223031236-a3549c8cb6a9 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/flatbuffers v1.12.0 // indirect
github.com/leesper/go_rng v0.0.0-20171009123644-5344a9259b21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xtgo/set v1.0.0 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20201222180813-1025295fd063 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gonum.org/v1/gonum v0.8.2 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gorgonia.org/cu v0.9.3 // indirect
gorgonia.org/dawson v1.2.0 // indirect
gorgonia.org/gorgonia v0.9.17 // indirect
gorgonia.org/tensor v0.9.17 // indirect
gorgonia.org/vecf32 v0.9.0 // indirect
gorgonia.org/vecf64 v0.9.0 // indirect
)
Loading