为了理解blender python游戏脚本,我目前尝试使用此链接中的FPSController结构构建一个可以围绕球体行走的场景.对于重力和FPSController方向,我尝试构造一个python控制器,目前看起来像这样:
def main():
print("Started")
controller = bge.logic.getCurrentController()
me = controller.owner
distance, loc, glob = me.getVectTo((0,0,0))
grav = controller.actuators['Gravity']
strength = me['Gravity']
force = strength*(distance*distance)*glob
grav.force = force
try:
rot = Vector((0,0,-1)).rotation_difference(glob).to_matrix()
except Exception as E:
print(E)
rot = (0,0,0)
rotZ = me.orientation
me.orientation = rot*rotZ
controller.activate(grav)
main()
Run Code Online (Sandbox Code Playgroud)
大致工作,直到任何角度超过180度,然后看起来不连续.我假设这来自rotate_difference是不连续的 - 关于数学类型和实用程序的blender文档没有说什么,我还没有想到四元数表示还没有看到连续映射是否可行 - 我想有更优雅的方式实现局部Z方向是连续的鼠标依赖,而局部X和Y方向依赖于某些给定的向量,但如何?
我最近从Python 2.7切换到Python 3.3,似乎在Python 2中,字典键的排序是任意的但是一致的,在Python 3中,用例如获得的字典的键的排序vars()
看起来是非确定性的.
如果我跑:
class Test(object): pass
parameters = vars(Test)
print(list(parameters.keys()))
Run Code Online (Sandbox Code Playgroud)
在Python 2.7和Python 3.3中,然后:
Python 2.7一直给我
['__dict__', '__module__', '__weakref__', '__doc__']
Run Code Online (Sandbox Code Playgroud)使用Python 3.3,我可以得到任何随机顺序 - 例如:
['__weakref__', '__module__', '__qualname__', '__doc__', '__dict__']
['__doc__', '__dict__', '__qualname__', '__module__', '__weakref__']
['__dict__', '__module__', '__qualname__', '__weakref__', '__doc__']
['__weakref__', '__doc__', '__qualname__', '__dict__', '__module__']
Run Code Online (Sandbox Code Playgroud)这种非决定论来自哪里?为什么会这样
list({str(i): i for i in range(10)}.keys())
Run Code Online (Sandbox Code Playgroud)
......在跑步之间保持一致,总是给予
['3', '2', '1', '0', '7', '6', '5', '4', '9', '8']
Run Code Online (Sandbox Code Playgroud)
......?
我正在尝试使用森林(或树)增强贝叶斯分类器(原始介绍,学习)python
(最好是python 3,但python 2也可以接受),首先学习它(结构和参数学习)然后使用它用于离散分类并获得具有缺失数据的那些特征的概率.(这就是为什么只有离散分类甚至好的天真分类器对我来说都不是很有用.)
我的数据进入的方式,我喜欢使用不完整数据的增量学习,但我甚至没有在文献中发现任何这两种情况,所以任何进行结构和参数学习和推理的东西都是好的回答.
似乎有一些非常独立且没有维护的python包大致朝着这个方向发展,但是我没有看到任何适度的近期(例如,我希望pandas
用于这些计算是合理的,但OpenBayes
几乎没有使用numpy
)我看到的任何东西似乎完全没有增强分类器.
那么,我应该在哪里寻找一些实现森林增强贝叶斯分类器的工作?在python类中是否有一个很好的Pearl传递消息传递算法的实现,或者不适合增强的贝叶斯分类器?是否有一个可读的面向对象的实现,用于学习和推理其他语言的TAN贝叶斯分类器,可以转换为python?
我知道现有的包,但发现不合适
milk
,它确实支持分类,但不支持贝叶斯分类器(我绝对需要分类和未指定功能的概率)pebl
,这只是结构学习scikit-learn
,它只学习朴素的贝叶斯分类器OpenBayes
自从有人将其移植numarray
到numpy
文档后,它几乎没有变化,文档可以忽略不计.libpgm
,声称支持一组甚至不同的东西.根据主要文档,它进行推理,结构和参数学习.除了似乎没有任何方法可以进行精确推理.bayesian
信念网络允许建立通用的贝叶斯网络并实现对它们的推断(精确和近似),这意味着它可用于构建TAN,但其中没有学习算法,以及BN的构建方式意味着实现参数学习比假设的不同实现更困难.我试图在contrib包(tf.contrib.ctc.ctc_loss)下使用Tensorflow的CTC实现,但没有成功.
这是我的代码:
with graph.as_default():
max_length = X_train.shape[1]
frame_size = X_train.shape[2]
max_target_length = y_train.shape[1]
# Batch size x time steps x data width
data = tf.placeholder(tf.float32, [None, max_length, frame_size])
data_length = tf.placeholder(tf.int32, [None])
# Batch size x max_target_length
target_dense = tf.placeholder(tf.int32, [None, max_target_length])
target_length = tf.placeholder(tf.int32, [None])
# Generating sparse tensor representation of target
target = ctc_label_dense_to_sparse(target_dense, target_length)
# Applying LSTM, returning output for each timestep (y_rnn1,
# [batch_size, max_time, cell.output_size]) and the final state of shape …
Run Code Online (Sandbox Code Playgroud) 在打包和分发Python包的文档中,它说要twine
与repository = https://upload.pypi.org/legacy/
in 一起使用.pypirc
.现在这个URL既是 - 从最后一点 - 一个传统的做事方式,一个不存在的方式:
$ twine register dist/scriptdoctest-0.1-py2.py3-none-any.whl
Registering package to https://upload.pypi.org/legacy/
Enter your username: MyUserName
Enter your password:
Registering scriptdoctest-0.1-py2.py3-none-any.whl
HTTPError: 410 Client Error: This API is no longer supported, instead simply upload the file. for url: https://upload.pypi.org/legacy/
Run Code Online (Sandbox Code Playgroud)
现在使用scriptdoctest.egg-info/PKG-INFO
注册包的首选和唯一方法,还是有其他方法来执行此操作twine
或其他一些CLI工具?
我正在使用Python Tensorflow中的音频数据训练LSTM网络.我的数据集是一堆波形文件,它们read_wavfiles
变成了numpy
数组的生成器.我决定尝试使用相同的数据集训练我的网络20次,并编写如下代码.
from with_hyperparams import stft
from model import lstm_network
import tensorflow as tf
def read_wavfile():
for file in itertools.chain(DATA_PATH.glob("**/*.ogg"),
DATA_PATH.glob("**/*.wav")):
waveform, samplerate = librosa.load(file, sr=hparams.sample_rate)
if len(waveform.shape) > 1:
waveform = waveform[:, 1]
yield waveform
audio_dataset = Dataset.from_generator(
read_wavfile,
tf.float32,
tf.TensorShape([None]))
dataset = audio_dataset.padded_batch(5, padded_shapes=[None])
iterator = tf.data.Iterator.from_structure(dataset.output_types,
dataset.output_shapes)
dataset_init_op = iterator.make_initializer(dataset)
signals = iterator.get_next()
magnitude_spectrograms = tf.abs(stft(signals))
output, loss = lstm_network(magnitude_spectrograms)
train_op = tf.train.AdamOptimizer(1e-3).minimize(loss)
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
for i …
Run Code Online (Sandbox Code Playgroud) 我在emacs中编写python.然而,不知何故,在emacs中运行的python解释器设法让我感到惊讶.
如果我写
print()
print(__name__)
print(__name__=='__main__')
if __name__ == '__main__':
print("indeed")
Run Code Online (Sandbox Code Playgroud)
在emacs缓冲区中,告诉emacs启动解释器并运行此缓冲区的内容,我得到一个包含的缓冲区
Python 3.3.5 (default, Mar 18 2014, 02:00:02)
[GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
>>>
__main__
True
>>>
Run Code Online (Sandbox Code Playgroud)
(两者__main__
并True
与打印语句输出;蟒蛇缓冲总是显示>>>
并打印后立即,我意识到了这一点,这不是一个问题.)
在命令行中,双方python
并python -i
显示"确实",符合市场预期.
如何Emacs的能够评价的不一致性__name__=='__main__'
来True
,而不是在执行里面的东西if __name__ == '__main__':
?如何重新配置它以便它不再这样做?
是否有更好的方法来获取GNU make
变量的第一个字符
FIRST=$(shell echo $(VARIABLE) | head -c 1)
Run Code Online (Sandbox Code Playgroud)
(这不仅笨重而且还调用外壳)?
我正在寻找一个合理的函数定义weighted_sample
,它不会为给定权重列表返回一个随机索引(这类似于
def weighted_choice(weights, random=random):
""" Given a list of weights [w_0, w_1, ..., w_n-1],
return an index i in range(n) with probability proportional to w_i. """
rnd = random.random() * sum(weights)
for i, w in enumerate(weights):
if w<0:
raise ValueError("Negative weight encountered.")
rnd -= w
if rnd < 0:
return i
raise ValueError("Sum of weights is not positive")
Run Code Online (Sandbox Code Playgroud)
给出一个具有恒定权重的分类分布)但随机抽样k
的那些,没有替换,就像random.sample
行为相比random.choice
.
就像weighted_choice
可以写成一样
lambda weights: random.choice([val for val, cnt in enumerate(weights) …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在python中存储和使用条件概率的好方法.
我正在考虑使用pandas
数据帧.如果某些条件概率X
的P(X=A|P1=1, P2=1) = 0.2
,P(X=B|P1=2, P2=1) = 0.9
等等,我会使用数据框
A B
P1 P2
1 1 0.2 0.8
2 0.5 0.5
2 1 0.9 0.1
2 0.9 0.1
Run Code Online (Sandbox Code Playgroud)
并给予的边缘概率P1
和P2
系列作为
1 0.4
2 0.6
Name: P1
1 0.7
2 0.3
Name: P2
Run Code Online (Sandbox Code Playgroud)
我想获得系列的边际概率X
,即系列
A 0.602
B 0.398
Name: X
Run Code Online (Sandbox Code Playgroud)
我可以得到我想要的东西
X = sum(
sum(
X.xs(i, level="P1")*P1[i]
for i in P1.index
).xs(j)*P2[j]
for j in P2.index
)
X.name="X"
Run Code Online (Sandbox Code Playgroud)
但这是不容易推广到更多的依赖关系,首先之间的不对称xs …
python ×8
tensorflow ×2
algorithm ×1
blender ×1
ctc ×1
dictionary ×1
emacs ×1
end-to-end ×1
gnu-make ×1
pandas ×1
probability ×1
pypi ×1
python-3.3 ×1
python-3.x ×1
random ×1
statistics ×1