dongyan3237 2015-02-06 20:37
浏览 10
已采纳

如何使用神经网络建立基本的Go项目?

I am super new go Go and need some help setting things up. First, the $GOPATH. It seems that all of my go projects should be in the same place on my machine? So I have that set:

$ echo $GOPATH
/sites/gopath

Inside, I set up the folders recommended:

$ ls -a /sites/gopath
.   ..  bin pkg src

Inside src, I have a folder called github.com, which has a folder in it called shamoons which has a folder in it called go-ann-test.

Inside that, I have a folder called autompg and inside that, I have a file called autompg.go.

Phew! That's a lot of set up for a project! But I'm going assume that I'm either doing it wrong or that it's somehow worth it.

In my autompg.go, I have:

package main

import (
  "fmt"
  "github.com/fxsjy/gonn"
)

func main() {
  nn := gonn.DefaultNetwork(2,3,1,true)
  inputs := [][]float64{
    []float64{0,0},
    []float64{0,1},
    []float64{1,0},
    []float64{1,1},
  }

  targets := [][]float64{
    []float64{0},//0+0=0
    []float64{1},//0+1=1
    []float64{1},//1+0=1
    []float64{2},//1+1=2
  }

  nn.Train(inputs,targets,1000)

  for _,p := range inputs{
    fmt.Println(nn.Forward(p))
  }
}

And when I type go install autompg from my go-ann-test folder, I get:

$ go install autompg 
can't load package: package autompg: cannot find package "autompg" in any of:
    /usr/local/Cellar/go/1.4.1/libexec/src/autompg (from $GOROOT)
    /sites/gopath/src/autompg (from $GOPATH)

So what am I doing wrong and how can I properly set up the project to accept the external package?

  • 写回答

1条回答 默认 最新

  • dongqufi82315 2015-02-06 20:42
    关注

    go install autompg from my go-ann-test folder:

    No, you need to go to the go-ann-test/autompg folder, and there type go install

    That will compile autompg.go into an executable autompg and put in in your $GOPATH/bin.

    Finally, you can add, commit and push to https://github.com/shamoons/go-ann-test.

    The OP Shamoon adds in the comments:

    I get

     autompg.go:35:3: no buildable Go source files in /sites/gopath/src/github.com/fxsjy/gonn
    

    That means a go get github.com/fxsjy/gonn is needed to import and compile github.com/fxsjy/gonn first.

    Considering that imported repo structure https://github.com/fxsjy/gonn, it actually needed:

    cd /sites/gopath/src/github.com/fxsjy/gonn/gonn
    go install 
    

    That means the actual import was:

    import github.com/fxsjy/gonn/gonn
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3