我试图在numpy中对某些数据进行线性拟合.
Ex(其中w是我对该值的样本数,即对于(x=0, y=0)I 点仅有1次测量且该测量值为2.2,但对于该点,(1,1)我有2次测量值为3.5.
x = np.array([0, 1, 2, 3])
y = np.array([2.2, 3.5, 4.6, 5.2])
w = np.array([1, 2, 2, 1])
z = np.polyfit(x, y, 1, w = w)
Run Code Online (Sandbox Code Playgroud)
那么,现在的问题是:w=w在这些情况下使用polyfit 是否正确,或者我应该使用w = sqrt(w)我应该使用的内容?
另外,我怎样才能从polyfit中得到拟合误差?
我对朱莉娅很新,但是我试试看,因为基准测试声称它比Python快得多.
我试图以["unixtime","price","amount"]格式使用一些股票价格数据
我设法加载数据并将unixtime转换为Julia中的日期,但现在我需要重新采样数据以使用olhc(开,高,低,收盘)作为价格和金额的总和,在特定时期朱莉娅(每小时,15分钟,5分钟等等):
julia> head(btc_raw_data)
6x3 DataFrame:
date price amount
[1,] 2011-09-13T13:53:36 UTC 5.8 1.0
[2,] 2011-09-13T13:53:44 UTC 5.83 3.0
[3,] 2011-09-13T13:53:49 UTC 5.9 1.0
[4,] 2011-09-13T13:53:54 UTC 6.0 20.0
[5,] 2011-09-13T14:32:53 UTC 5.95 12.4521
[6,] 2011-09-13T14:35:04 UTC 5.88 7.458
Run Code Online (Sandbox Code Playgroud)
我看到有一个名为Resampling的软件包,但它似乎只接受一个时间段,只有我想要输出数据的行数.
还有其他选择吗?
我正在尝试使用websockets访问一些数据,但我无法真正解决websockets文档中给出的示例.
我有这个代码,并希望在类中转换它
import websocket
import thread
import time
def on_message(ws, message):
print message
def on_error(ws, error):
print error
def on_close(ws):
print "### closed ###"
def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
ws.send("Hello %d" % i)
time.sleep(1)
ws.close()
print "thread terminating..."
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://echo.websocket.org/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
Run Code Online (Sandbox Code Playgroud)
我们的想法是在类中使用所有websocket功能,这样我就可以创建该类的对象.
我试着开始这样做,但我甚至无法通过这个:
class MySocket(object):
def __init__(self):
websocket.enableTrace(True)
self.ws = websocket.WebSocketApp("ws://echo.websocket.org:12300/foo",
on_message = on_message,
on_error = …Run Code Online (Sandbox Code Playgroud) Apple提供的用于安装Xcode 4.3命令行工具的软件包已损坏,我似乎需要它,因为我正在开发一些命令行工具.
是否有人为Apple的Xcode 4.3找到了另一个命令行软件包,该软件包适用于该主题?
我正在尝试为黑白出版物制作一些图形,我在使用轴时遇到了一些问题.
我需要在轴(而不是网格)中绘制数据的子图,并且我通过使用annotation_logticks(base=2, sides="trbl")with base 2 找到了一个技巧,因为我的数据与日志无关.
但这似乎不适用于y轴,它采用日期格式类型(xts).
到目前为止我得到的图是下面的图,我需要的是删除背景网格(该部分应该很容易)并在y轴上添加刻度(这对我来说是困难的部分).

这是我用来做图表的代码:
ratio_plot_start_time = "01:45"
ratio_plot_end_time = "02:10"
channelNo = 1
p <- ggplot(onsetratios, aes(x=ratio*100, y=onset)) + geom_point(aes(y=onset))
p <- p + ylim(as.POSIXct(paste(date, ratio_plot_start_time, sep=" ")), as.POSIXct(paste(date, ratio_plot_end_time, sep=" ")))
p <- p + geom_errorbar(aes(ymin=onset-error, ymax=onset+error), width=0.0)
p <- p + xlab(expression("percent of peak counts"))+ ylab(expression("UT Time (2012 May 17)")) + theme(aspect.ratio = 2/(1+sqrt(5)))
p <- p + theme_bw(base_size = 14, base_family = "Helvetica") + annotate("text",x=max(onsetratios$ratio),y=as.POSIXct(paste(date, ratio_plot_end_time, sep=" ")),vjust=4,hjust=2,label=paste("F", channelNo, "'")) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用不同的参数同时(大约或当然)运行多个函数,并在每分钟开始时重复该操作。
我设法得到了一个asyncio运行示例,在该示例中我callback使用不同的参数在特定时间运行一个函数,但我无法弄清楚如何在非常特定的时间运行它(并永远运行它)(即我想在每分钟开始时运行它,所以在 19:00:00、19:01:00 等等)。
Asynciocall_at应该能够做到这一点,但它使用的时间格式不是标准的 Python 时间格式,我无法弄清楚将该时间格式指定为下一分钟的 00 秒。
import asyncio
import time
def callback(n, loop, msg):
print(msg)
print('callback {} invoked at {}'.format(n, loop.time()))
async def main(loop):
now = loop.time()
print('clock time: {}'.format(time.time()))
print('loop time: {}'.format(now))
print('registering callbacks')
loop.call_at(now + 0.2, callback, 1, loop, 'a')
loop.call_at(now + 0.1, callback, 2, loop, 'b')
loop.call_soon(callback, 3, loop, 'c')
await asyncio.sleep(1)
event_loop = asyncio.get_event_loop()
try:
print('entering event loop')
event_loop.run_until_complete(main(event_loop))
finally:
print('closing event loop')
event_loop.close()
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Python 生成的图像与文件中的图像/照片进行比较。
到目前为止,最好的方法是在 Matplotlib 中生成一个图形,然后将其转换为 numpy 数组,并将这些值与我从图像中获得的值进行比较。
我得到了以下代码,将 Matplotlib 图转换为具有 RGB 通道的 3D numpy 数组:
def fig2data ( fig ):
"""
@brief Convert a Matplotlib figure to a 3D numpy array with RGB channels and return it
@param fig a matplotlib figure
@return a numpy 3D array of RGB values
"""
# draw the renderer
fig.canvas.draw ( )
# Get the RGBA buffer from the figure
w,h = fig.canvas.get_width_height()
buf = numpy.fromstring ( fig.canvas.tostring_rgb(), dtype=numpy.uint8 )
buf.shape = ( …Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用Unity3d的教程,我已经走到了尽头.
我相信在较新版本的Unity中发生了一些变化,因为教程看起来像我正在做的那样工作得很好.
我有一个输入字段UI组件,我想在每次更改时调用C#函数.
根据教程,我只需要使用输入字段(脚本)的"On Value Change"属性,并告诉它调用一个以a string作为参数的函数.
public string playerName;
public void setName (string name)
{
playerName = name;
Debug.Log("Set playerName: "+name, gameObject);
Debug.Log("Get playerName: "+playerName, gameObject);
}
Run Code Online (Sandbox Code Playgroud)
然而,这没有任何作用,我的playerName财产总是空的,我没有收到任何东西name.
我该怎么做呢?我已经看到一个答案在Start()函数中设置一个监听器,然后UnityEvent在这里使用:从输入字段中获取文本
但是有没有其他方法可以使用Unity3d图形编辑器来完成这项工作,而不需要编写如此多的代码?
我正在nolearn做一个神经网络,这是一个使用烤宽面条的Theano图书馆.
我不明白如何定义自己的成本函数.
输出层只有3个神经元[0, 1, 2],我希望它在给出1或2时大部分都是肯定的,否则 - 如果它不能确定1,2,则简单地返回0.
所以,我提出了一个成本函数(需要调整),其成本是1和2的两倍而不是0,但我无法理解如何告诉网络.
# optimization method:
from lasagne.updates import sgd
update=sgd,
update_learning_rate=0.0001
Run Code Online (Sandbox Code Playgroud)
这是更新的代码,但是如何告诉SGD使用我的成本函数而不是它自己的?
编辑: 完整的网络代码是:
def nn_loss(data, x_period, columns, num_epochs, batchsize, l_rate=0.02):
net1 = NeuralNet(
layers=[('input', layers.InputLayer),
('hidden1', layers.DenseLayer),
('output', layers.DenseLayer),
],
# layer parameters:
batch_iterator_train=BatchIterator(batchsize),
batch_iterator_test=BatchIterator(batchsize),
input_shape=(None, int(x_period*columns)),
hidden1_nonlinearity=lasagne.nonlinearities.rectify,
hidden1_num_units=100, # number of units in 'hidden' layer
output_nonlinearity=lasagne.nonlinearities.sigmoid,
output_num_units=3,
# optimization method:
update=nesterov_momentum,
update_learning_rate=5*10**(-3),
update_momentum=0.9,
on_epoch_finished=[
EarlyStopping(patience=20),
],
max_epochs=num_epochs,
verbose=1,
# Here are the important parameters for multi labels
regression=True,
# objective_loss_function=multilabel_objective, …Run Code Online (Sandbox Code Playgroud) 我已经浏览了文档并查看了问题:
如何使用vim(键绑定)与Visual Studio Code vim扩展,我仍然无法在Vim扩展名中定义新键Visual Studio Code.
我正在尝试两件事settings.json.试图删除一个完整的标签 - 而不是只有一个空格(如vim) - 使用退格键.
"vim.insertModeKeyBindings": [
{
"before": "backspace",
"after": "shift+backspace"
}
]
Run Code Online (Sandbox Code Playgroud)
并且还要在编辑器窗格之间进行更改space, w, w(例如使用引导键):
"vim.keybindings": [
{
"key": ["space", "w", "w"],
"command": "workbench.action.navigateEditorGroups",
"when": "editorFocus"
}
]
Run Code Online (Sandbox Code Playgroud)
但我无法让任何人工作.