Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created Mar 31, 2018
Embed
What would you like to do?
package main
import (
"encoding/gob"
"fmt"
"log"
"math"
"os"
"gonum.org/v1/gonum/mat"
)
func main() {
frp, err := os.Open("../data/q85.proj.txt")
if err != nil {
log.Fatal(err)
}
defer frp.Close()
dec := gob.NewDecoder(frp)
var proj mat.Dense
err = dec.Decode(&proj)
if err != nil {
log.Fatal(err)
}
frd, err := os.Open("../data/q85.dictt.txt")
if err != nil {
log.Fatal(err)
}
defer frd.Close()
dec = gob.NewDecoder(frd)
dict := make(map[string]int)
err = dec.Decode(&dict)
if err != nil {
log.Fatal(err)
}
v1 := proj.RowView(dict["United_States"])
v2 := proj.RowView(dict["U.S"])
fmt.Println(cos(v1, v2))
}
func cos(a, b mat.Vector) float64 {
return mat.Dot(a, b) / (math.Sqrt(mat.Dot(a, a)) * math.Sqrt(mat.Dot(b, b)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment