Exemple #1
0
func cost2(params score.Parameters, trainset []TrainItem) float64 {
	var totalScore float64
	enerchan := make(chan float64, len(trainset))
	// rankchan := make(chan float64, len(trainset))
	exp := make([]float64, len(trainset))
	obs := make([]float64, len(trainset))
	enerScore := 0.0
	// rankScore := 0.0
	for i := 0; i < len(trainset); i++ {
		go func(i int) {
			// protein := protein.LoadMol2("./traindata/" + traindata[i].Receptor)
			protein := trainset[i].Receptor
			// pos := ligand.LoadMol2("./traindata/" + traindata[i].Positive)
			pos := trainset[i].Positive
			total := params.Score(&protein, &pos)

			// rk := 0.0
			// for j := 0; j < len(trainset[i].Negatives); j++ {
			// 	// neg := ligand.LoadMol2("./traindata/" + traindata[i].Negatives[j])
			// 	neg := trainset[i].Negatives[j]
			// 	negTotal := params.Score(&protein, &neg)
			// 	if negTotal <= total {
			// 		rk += 1.0
			// 	}
			// }
			exp[i] = trainset[i].Energy
			obs[i] = total
			enerchan <- ((trainset[i].Energy - total) * (trainset[i].Energy - total))
			// rankchan <- rk
		}(i)
	}

	for i := 0; i < len(trainset); i++ {
		enerScore += <-enerchan
		// rankScore += <-rankchan
	}
	corr := stat.Correlation(exp, obs, nil)

	// totalScore = enerScore/(corr*corr) + (enerScore / (corr * corr) * rankScore)
	// totalScore = enerScore*(2000.0-1999.0*corr) + (math.Sqrt(enerScore) * (2000.0 - 1999.0*corr) * rankScore * 1000000.0)
	totalScore = enerScore * (2000.0 - 1999.0*corr)
	// fmt.Printf("PKD %f - Rank %f - Corr %f - TOTAL %f\n", enerScore, rankScore, corr, totalScore)
	fmt.Printf("Energy %f - Corr %f - TOTAL %f\n", math.Sqrt(enerScore/float64(len(trainset))), corr, totalScore)
	return totalScore
}
Exemple #2
0
func nm(params *score.Parameters, l *ligand.Ligand, p *protein.Protein) {
	orig := l.Center()
	method := &optimize.NelderMead{}
	method.SimplexSize = 0.01
	initX := []float64{orig[0] + rand.Float64(), orig[1] + rand.Float64(), orig[2] + rand.Float64(), 0.0, 0.0, 0.0}
	problem := &optimize.Problem{}
	fmt.Println("INICIO", params.Score(p, l))
	fmt.Println("Center: ", orig)
	problem.Func = func(x []float64) float64 {
		l.Move(x[0], x[1], x[2], x[3]-l.Angles[0], x[4]-l.Angles[1], x[5]-l.Angles[2])
		fmt.Println(x)
		sc := params.Score(p, l)
		fmt.Println(sc)
		return sc
	}
	result, err := optimize.Local(*problem, initX, nil, method)
	if err != nil {
		fmt.Println("Erro minimização:", err)
	}
	fmt.Println("###RESULT:", result)
	fmt.Println("Location:", result.Location.X)
	l.Move(result.Location.X[0], result.Location.X[1], result.Location.X[2], result.Location.X[3], result.Location.X[4], result.Location.X[5])
	fmt.Println(params.Score(p, l))
	l.SavePDB("")
}
Exemple #3
0
func cost3(params score.Parameters, trainset []TrainItem) float64 {
	var totalScore float64
	// enerchan := make(chan float64, len(trainset))
	rankchan := make(chan float64, len(trainset))
	exp := make([]float64, len(trainset))
	obs := make([]float64, len(trainset))
	// nNegatives := 0.0
	// enerScore := 0.0
	rankScore := 0.0
	for i := 0; i < len(trainset); i++ {
		go func(i int) {
			protein := trainset[i].Receptor
			pos := trainset[i].Positive
			total := params.Score(&protein, &pos)
			rk := 0
			for j := 0; j < len(trainset[i].Negatives); j++ {
				neg := trainset[i].Negatives[j]
				negTotal := params.Score(&protein, &neg)
				if negTotal <= total {
					rk += 1
					if rk == 5 {
						break
					}
					if rk > 5 {
						fmt.Println("F**K")
					}
				}

			}
			exp[i] = trainset[i].Energy
			obs[i] = total
			// enerchan <- ((trainset[i].Energy - total) * (trainset[i].Energy - total))
			rankchan <- float64(rk) / 5.0
			// nNegatives += float64(len(trainset[i].Negatives))
		}(i)
	}

	// var ranktmp float64
	for i := 0; i < len(trainset); i++ {
		rankScore += <-rankchan
	}
	// 	ranktmp = <-rankchan
	// 	if ranktmp > rankScore {
	// 		rankScore = ranktmp
	// 	}
	// 	// enerScore += <-enerchan
	// 	//
	// }

	rankScore = rankScore / float64(len(trainset))

	corr := stat.Correlation(exp, obs, nil)
	corrSquared := 0.0
	if corr > 0.0 {
		corrSquared = corr * corr
	}

	// totalScore = enerScore/(corr*corr) + (enerScore / (corr * corr) * rankScore)
	// totalScore = enerScore*(2000.0-1999.0*corr) + (math.Sqrt(enerScore) * (2000.0 - 1999.0*corr) * rankScore * 1000000.0)
	totalScore = (math.Pow(1-corrSquared, 2) + math.Pow(rankScore, 2)) * 1000
	// fmt.Printf("PKD %f - Rank %f - Corr %f - TOTAL %f\n", enerScore, rankScore, corr, totalScore)
	fmt.Printf("Corr %f - Corr^2 %f - Rank %f - TOTAL %f\n", corr, corrSquared, rankScore, totalScore)
	return totalScore
}