小编you*_*his的帖子

R:VAR模型精度误差

我有两个问题.(注:问题的第一部分已在下面的评论中得到解决)

  1. 首先,我试图根据Rob Hyndman的本教程确定VAR预测的平均绝对误差,并收到以下错误消息:

    Error in `-.default`(fcast[['mean']], dxnext) :
      non-numeric argument to binary operator
    
    Run Code Online (Sandbox Code Playgroud)

    我相信我已设法将其追踪到VAR的输出,这是非数字的,并且似乎导致了问题.

    有解决方法吗?

  2. 其次,这段代码需要为双向和多变量模型的工作,因此我怀疑我是否应该使用的长度dxn作为教程提出,或一个变量的长度,因为这是代表长度给定时限.问题在于dx给定预测长度(在这种情况下为12)的循环中的长度和如何处理.任何输入将不胜感激.

下面是包含示例数据和所需包的代码,因此可以复制错误.

require("forecast")
require("vars")

x <- rnorm(70)
y <- rnorm(70)

dx <- cbind(x,y)
dx <- as.ts(dx)

# Forecast Accuracy
k <- 58 # data length less forecast horison (as minimum)
n <- length(dx)
mae <- matrix(NA, n-k, 12)
st <- tsp(dx)[1]+(k-2)/12

for (i in 1:(n-k)) {
 dxshort <- window(dx, end=st+i/12)
 dxnext <- window(dx, start=st + …
Run Code Online (Sandbox Code Playgroud)

statistics arguments r

7
推荐指数
0
解决办法
587
查看次数

操作 TCP 标头中的 ISN 编号的最有效方法

我目前正在尝试编写一个程序,该程序将能够创建稳定的 TCP 连接并完全控制 ISN 编号。我一直在用 C 语言写作,现在我非常有限的知识已经达到了极限,我想知道是否有更好的方法来做到这一点。

我尝试的是手动构建标头,使用原始套接字发送和接收数据包,而不会受到内核干扰,这是一个挑战。

因此,无论使用哪种语言,您认为操纵 ISN 最有效、最简单的方法是什么?

c network-programming tcp header low-level

5
推荐指数
1
解决办法
2710
查看次数

C - 在RAM中运行程序

我有一个程序,使用一次性密码加密将两个文件进行异或.由于密钥文件具有如此敏感的特性,我不希望密钥文件的任何痕迹出现在计算机硬盘驱动器上,因为这可能会危及安全性.

问题是,如何在RAM中运行程序以避免在HD上留下任何痕迹?或者,从闪存驱动器运行程序是否包含闪存驱动器的密钥文件的痕迹?

下面是程序中如何处理密钥文件:

/* Check if keyfile can be opened. */
if((keyfile = fopen(argv[3], "rb"))== NULL)
{
printf("Can't open keyfile.\n");
printf("Please enter a valid filename.\n"); 
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
perror("Error");
return(1);
}                               

/* Get size of keyfile */
fstat(fileno(keyfile), &keybuf);

/* Check if keyfile is the same size as, or bigger than the sourcefile */
if((keybuf.st_size) < (statbuf.st_size))
{
printf("Source file is larger than keyfile.\n");
printf("This significantly reduces cryptographic strength.\n");
printf("Do you wish to continue? (Y/N)\n");
fgets(buffer, …
Run Code Online (Sandbox Code Playgroud)

c ram file hard-drive

5
推荐指数
1
解决办法
285
查看次数

c - pcap过滤器表达式

我想知道这个表达式中的输入数据是如何实际工作的.

char *filter = "dst host 172.17.14.90 and ip";
Run Code Online (Sandbox Code Playgroud)

根据我的理解,该dest host位和以下IPv4地址定义了接收到的数据包应该寻址的地址.

在这一点上,手册页有点令人困惑:

dst host host
如果数据包的IPv4/v6目标字段是主机,则为True,可以是地址或名称.

http://www.manpagez.com/man/7/pcap-filter/

这是什么意思?至于那and ip一点我没有任何线索.

c network-programming tcp filter pcap

4
推荐指数
1
解决办法
2976
查看次数

Windows 等效于 sys/mman.h

尝试在 Win64 上编译我的 C 代码时遇到问题。更具体地说,编译器找不到sys/mman.h头文件,据我所知,它只能在 Unix 环境中找到。

我已经知道这是处理内存分配。

我可以使用 Windows 的等价物来移植代码(第一次尝试)?

导致问题的代码:

/* Allocate memory required by processes */
buf = (int*) malloc (sizeof(int));
if (!buf)
{
    perror("Error");
    free (buf);
    return -3;
}

/* Lock down pages mapped to processes */
puts("Locking down processes.");
if(mlockall (MCL_CURRENT | MCL_FUTURE) < 0)
{
    perror("mlockall");
    free (buf);
    return -4;
}
Run Code Online (Sandbox Code Playgroud)

c windows porting memory-management

4
推荐指数
1
解决办法
1万
查看次数

R:Quantstrat TxnFees乘数

我正试图在R的Quantstrat包中运行回测策略.该工具为小麦期货,报价为美分.合约规模为5000蒲式耳.因此我添加了以下代码.

future(symbols, 
      currency = "USD",
      tick_size = 0.25,
      multiplier = 50) 
Run Code Online (Sandbox Code Playgroud)

然而,当运行模型时,当利润太小时,它似乎会产生损失,这促使我看看如何在印刷包中计算交易费用,如github上的此代码所示.

#' @param ConMult Contract/instrument multiplier for the Symbol if it is not defined in an instrument specification
Run Code Online (Sandbox Code Playgroud)

这是否意味着当我指定时.txnfees <- -10,税费是50*-10 = -500,在这种情况下我应该指定TxnFees为-0.2.如何为每个订单指定设定金额?

r quantstrat financialinstrument

2
推荐指数
1
解决办法
627
查看次数

c - 初始化从指针生成整数而没有强制转换和另外2个编译器错误

所以我收到了这个警告:

initialization makes integer from pointer without a cast
Run Code Online (Sandbox Code Playgroud)

在下面的代码中:

void receive(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *buffer)

{

const int one = 1;

int LEN = args;      /* THIS IS THE LINE */

struct ipheader *ip;

struct tcpheader *tcp;
Run Code Online (Sandbox Code Playgroud)

说实话,小新手我不知道该怎么办,因为几乎所有的搜索都会返回makes pointer from integer.

我也收到这些编译器消息:

/tmp/cci6u7NH.o: In function `main':
ChannelBunny.c:(.text+0x448): undefined reference to `pthread_create'
ChannelBunny.c:(.text+0x4b7): undefined reference to `pthread_join'
/tmp/cci6u7NH.o: In function `receive':
ChannelBunny.c:(.text+0xcb6): undefined reference to `nthol'
ChannelBunny.c:(.text+0xcdf): undefined reference to `nthol'
collect2: ld returned …
Run Code Online (Sandbox Code Playgroud)

c compiler-construction gcc warnings pointers

1
推荐指数
1
解决办法
4万
查看次数

c - 分段错误(核心转储)指针问题

当我尝试使用参数运行程序时,我收到了分段错误错误.现在我通过GDB运行它并找到有问题的行,它看起来像这样:

*dstip = (*optarg);
Run Code Online (Sandbox Code Playgroud)

原型是:

char *dstip;
Run Code Online (Sandbox Code Playgroud)

最后它被称为这一行:

char *filter = ("ip dest host %s", dstip);
Run Code Online (Sandbox Code Playgroud)

现在回过头来看,我并不感到惊讶它看起来不起作用......坦率地说,错误地通过删除这些行(并改变过滤器文本)来解决问题.但是,我需要在错误消息过滤器中显示的IPv4地址将被使用,并且对指针没用,并且来回尝试过不同的东西我无法正确使用它.也就是说,我只能得到warning initialization makes pointer from integer类似的......怎么办?

c pointers ip-address segmentation-fault

0
推荐指数
1
解决办法
1019
查看次数

C - scanf行为不端

当使用第一个scanf()并回答Y时,第二个scanf()会直接跳到"No option selected.退出......".当密钥文件大于源文件并且最后一个scanf正常工作时,也会出现该消息.所以我在这里不知所措,出了什么问题?(代码编译得很好,所以随意尝试)

编辑:对于downvoters至少发布一个理由会有所帮助.我不是一个非常优秀的程序员,只是想在这里学习.

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
struct stat statbuf;
struct stat keybuf;

int key;
int data;
int output;
int count;
char ans;
FILE * keyfile;
FILE * sourcefile;
FILE * destfile;

if(argc<4)
{
printf("OTP-Bunny 1.0\n");
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
return (0);
}

/* Check number of arguments. */
if(argc>4)
{
printf("Too many arguments.\n");
printf("USAGE: OTP <source file> <output file> <keyfile>\n");
return(1);
}

/* Check if sourcefile can …
Run Code Online (Sandbox Code Playgroud)

c scanf

0
推荐指数
1
解决办法
248
查看次数

C程序忽略if​​语句包含sizeof

我目前正在编写一个简单的小型一次性垫程序.我希望它在keyfile小于source文件时警告用户,但是当我运行它时我的程序只是忽略它.

/* Check if keyfile is the same size as, or bigger than the sourcefile */
if(sizeof keyfile < sizeof sourcefile)
{
printf("Source file is larger than keyfile.\n");
printf("This significantly reduces cryptographic strength.\n");
printf("Do you wish to continue? (Y/N)\n");
scanf("%c", &ans);
if(ans == 'n' || ans == 'N')
    {
    return (1);
    }
if(ans == 'y' || ans == 'Y')
    {
    printf("Proceeding with Encryption/Decryption.\n");
    }
Run Code Online (Sandbox Code Playgroud)

我怀疑问题在于我的使用sizeof,但我不知道其他任何选择?有关如何更改我的代码以使其工作的任何建议?

编辑:我已尽力增加fstat我的能力,但它仍然以同样的方式作出反应......这就是我所做的:

/* Get size of sourcefile. */ …
Run Code Online (Sandbox Code Playgroud)

c if-statement file sizeof

-1
推荐指数
2
解决办法
317
查看次数