Пример #1
0
 def tosimilaritypvalues(self, axis, metric='cosine'):
     if axis == 0:
         return datamatrix(rowname=self.rowname,
                           rowlabels=self.rowlabels.copy(),
                           columnname=self.rowname,
                           columnlabels=self.rowlabels.copy(),
                           matrixname=self.rowname + '-' + self.rowname +
                           '_' + metric + '_similarity_derived_from_' +
                           self.matrixname,
                           matrix=mlstats.corr(self.matrix,
                                               axis=axis,
                                               metric=metric,
                                               getpvalues=True)[1],
                           rowmeta=copy.deepcopy(self.rowmeta),
                           columnmeta=copy.deepcopy(self.rowmeta))
     elif axis == 1:
         return datamatrix(rowname=self.columnname,
                           rowlabels=self.columnlabels.copy(),
                           columnname=self.columnname,
                           columnlabels=self.columnlabels.copy(),
                           matrixname=self.columnname + '-' +
                           self.columnname + '_' + metric +
                           '_similarity_derived_from_' + self.matrixname,
                           matrix=mlstats.corr(self.matrix,
                                               axis=axis,
                                               metric=metric,
                                               getpvalues=True)[1],
                           rowmeta=copy.deepcopy(self.columnmeta),
                           columnmeta=copy.deepcopy(self.columnmeta))
     else:
         raise ValueError('invalid axis')
Пример #2
0
                # single bead move
                new_x0 = old_x0
                new_x1 = old_x1 + np.random.randn() * opt_sig(omega, tau, lam)
                path[islice] = new_x0
                path[(islice + 1) % nslice] = new_x1

                # calculate action change
                new_action = action(path, omega, beta, lam)
                prob = np.exp(-(new_action - old_action))  # action = -ln_rho

                # accept or recject
                if np.random.rand() < prob:
                    naccept += 1
                else:
                    path[islice] = old_x0
                    path[(islice + 1) % nslice] = old_x1
                # end if prob
                nmove += 1
            # end for islice
        # end for istep
    # end for isample

    np.savetxt('pos.dat', pos)
    pos2 = pos[nequil:] * pos[nequil:]
    x2eq = x2[nequil:]
    accept = float(naccept) / nmove  #float(naccept)/nsample/nslice/block_size
    print(omega, beta, sig, accept, corr(pos2), np.mean(x2eq), error(x2eq))

# end __main__
Пример #3
0
    return args.omega, args.beta, args.lam, args.sig, args.nequil, args.nsample, args.use_opt_sig, args.block_size


# end def

if __name__ == '__main__':

    omega, beta, lam, sig, nequil, nsample, use_opt_sig, block_size = parse_inputs(
    )
    # calculate optimal step size
    if use_opt_sig:
        sig = opt_sig(omega, beta, lam)
    # end if

    accept, x2 = sample_1d_harmonic_analytic(ln_rho, omega, beta, lam, sig,
                                             block_size)

    x2eq = x2[nequil:]
    fmt = "{omega:6.2f}  {beta:4.2f}  {sig:4.2f}  {accept:3.2f}  {corr:3.1f}  {x2:4.6f}  {x2e:4.6f}"
    output = fmt.format(omega=omega,
                        beta=beta,
                        sig=sig,
                        accept=accept,
                        corr=corr(x2eq),
                        x2=np.mean(x2eq),
                        x2e=error(x2eq))
    print(output)
    #print( omega,beta,sig,accept,corr(x2eq),np.mean(x2eq),error(x2eq) )
    np.savetxt('ax2.dat', x2)
# end __main__
Пример #4
0
def least_squares_fit(x, y):
    """x와 y가 학습 데이터로 주어졌을 때
	오류의 제곱 값을 최소화해 주는 알파와 베타를 계산"""
    beta = corr(x, y) * stdev(y) / stdev(x)
    alpha = mean(y) - beta * mean(x)
    return alpha, beta