Skip to content

Instantly share code, notes, and snippets.

myData=c(1,1,1,1,1,1,1,1,1,1,1,0,0,0)
# 尝试1万个不同的参数
tryn = 1e4
Theta = sort(runif(tryn))
pTheta = 1/tryn
z = sum( myData==1 )
N = length( myData )
# 似然函数
pDataGivenTheta = Theta^z * (1-Theta)^(N-z)
pData = sum( pDataGivenTheta * pTheta )
# 假设七个岛人口数分布如下
# 1:7/sum(1:7)
# 尝试10万次旅行
trajLength = 1e5
trajectory = rep( 0 , trajLength )
trajectory[1] = 3 # 第一次在第3个岛上
target = function(currentPosition,proposedJump){
tartetposition = currentPosition+proposedJump
p = min(1,tartetposition/currentPosition)
import numpy as np
x = np.random.randn(100)
y = 2*x + np.random.randn(100)
%load_ext rpy2.ipython
%%R -i x,y -w 500 -h 300
df <- data.frame(x,y)
m <- lm(y~x)
inter <- m$coef[1]
#原始的方式
lines = [line.split(',') for line in open('iris.csv')]
df = [[float(x) for x in line[:4]] for line in lines[1:]]
#使用numpy包
import numpy as np
lines = np.loadtxt('iris.csv',delimiter=',',dtype='str')
df = lines[1:,:4].astype('float')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"metadata": {
"name": "",
"signature": "sha256:2683cac2187cd419060efce81038e1475914d0619d8aab1b43ac49dfcca7322f"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
from collections import Counter
class Tank():
def __init__(self,value):
self.tab = dict(Counter(value))
def Values(self):
return self.tab.keys()
def Mult(self, x, factor):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.