以下树:
已从以下矩阵中获得
> mat
7 23 47 41 31
7 23 53 41 31
7 23 53 41 37
7 29 47 41 31
7 29 47 41 37
7 29 53 41 31
7 29 53 41 37
11 29 53 41 31
11 29 53 41 37
Run Code Online (Sandbox Code Playgroud)
将每个"mat"列作为树的一个级别.如果'data'是存储矩阵'mat'的数据帧
V1 V2 V3 V4 V5
7 23 47 41 31
7 23 53 41 31
7 23 53 41 37
7 29 47 41 31
7 29 47 41 37 …Run Code Online (Sandbox Code Playgroud) 引入近似熵来量化时间序列中的规律性和波动的不可预测性.
功能
approx_entropy(ts, edim = 2, r = 0.2*sd(ts), elag = 1)
Run Code Online (Sandbox Code Playgroud)
从包中pracma,计算出时间序列的近似熵ts.
我有一个时间序列矩阵(每行一个系列)mat,我会估计每个矩阵的近似熵,将结果存储在一个向量中.例如:
library(pracma)
N<-nrow(mat)
r<-matrix(0, nrow = N, ncol = 1)
for (i in 1:N){
r[i]<-approx_entropy(mat[i,], edim = 2, r = 0.2*sd(mat[i,]), elag = 1)
}
Run Code Online (Sandbox Code Playgroud)
但是,如果N很大,这段代码可能会太慢.建议加快速度吗?谢谢!
我有如下数据:
directions <- c("North", "East", "South", "South")
x<-factor(directions, levels= c("North", "East", "South", "West"))
cities <- c("New York","Rome","Paris","London")
y<-factor(cities, levels= c("New York","Rome","Paris","London"))
Run Code Online (Sandbox Code Playgroud)
如何计算 和 之间的斯皮尔曼等级相关x性y?
编辑
正如 @user20650 和 @dcarlson 评论所建议的,变量必须具有排名,使得一个值大于或小于另一个值。情况确实如此,因为North等East是根据其在文档中的存在情况排序的关键字。
功能R
tseriesChaos::false.nearest(series, m, d, t, rt=10, eps=sd(series)/10)
Run Code Online (Sandbox Code Playgroud)
实现虚假最近邻算法来帮助确定最佳嵌入维度。
我想将其应用到以下系列:
dput(x)
c(0.230960354326456, 0.229123906233121, 0.222750351085665, 0.230096143459004,
0.226315220913903, 0.228151669007238, 0.225775089121746, 0.229447985308415,
0.230096143459004, 0.232256670627633, 0.23722588311548, 0.236361672248029,
0.231716538835476, 0.229231932591552, 0.229880090742141, 0.229447985308415,
0.236901804040186, 0.234525224154694, 0.236577724964891, 0.240574700226855,
0.238090093982932, 0.233552986928811, 0.235929566814303, 0.228799827157827,
0.224694825537431, 0.225775089121746, 0.224694825537431, 0.221129955709193,
0.214540347844874, 0.213352057902128, 0.21054337258291, 0.208706924489575,
0.211083504375068, 0.212487847034676, 0.20903100356487, 0.206654423679378,
0.213027978826834, 0.211083504375068, 0.216160743221346, 0.213244031543697,
0.214324295128011, 0.216160743221346, 0.215512585070757, 0.218753375823701,
0.215836664146052, 0.225126930971157, 0.228367721724101, 0.23128443340175,
0.240574700226855, 0.244139570055093, 0.246732202657448, 0.248028518958626,
0.246300097223723, 0.245976018148428, 0.241762990169601, 0.245976018148428,
0.248892729826078, 0.258831154801772, 0.265744841741385, 0.259803392027655,
0.258831154801772, 0.261855892837852, 0.262504050988441, 0.262071945554715,
0.257102733066868, 0.270065896078643, 0.276655503942962, 0.280544452846495, …Run Code Online (Sandbox Code Playgroud) 树遍历是指以系统方式访问树数据结构中的每个节点的过程.在postorder下面的图像中遍历
回报A, C, E, D, B, H, I, G, F (left, right, root).PREORDER遍历的Prolog代码是
preorder(tree(X,L,R),Xs) :-
preorder(L,Ls),
preorder(R,Rs),
append([X|Ls],Rs,Xs).
preorder(void,[]).
Run Code Online (Sandbox Code Playgroud)
我想修改上面的代码来实现postorder遍历.
此代码根据参与者和关系的数据帧绘制图表。
library(igraph)
actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David",
"Esmeralda"))
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
friendship=c(4,15,5,2,11,1))
g <- graph_from_data_frame(relations, directed=TRUE, vertices=actors)
plot(g)
Run Code Online (Sandbox Code Playgroud)
结果是:
我想根据 的值更改弧的厚度(而不是长度)relations$friendship。
让我们考虑以下数组
x<-c(0.385, 0.385, 0.311, 0.311, 0.585, 0.585, 0.352,
0.352, 0.359, 0.359, 0.627, 0.627, 0.329, 0.329,
0.296, 0.296, 0.504, 0.504, 0.456, 0.456, 0.281,
0.281, 0.335, 0.335, 0.356, 0.356, 0.368, 0.368,
0.326, 0.326, 0.487, 0.487, 0.323, 0.323, 0.710,
0.710, 0.437, 0.437, 0.387, 0.387, 0.550, 0.550,
0.363, 0.363, 0.342, 0.342, 0.344, 0.344, 0.516,
0.516, 0.351, 0.351, 0.282, 0.282, 0.444, 0.444,
0.356, 0.356, 0.437, 0.437, 0.369, 0.369, 0.282,
0.282, 0.312, 0.312, 0.336, 0.336, 0.556, 0.556,
0.464, 0.464, 0.274, 0.274, 0.352, 0.352, 0.362,
0.362, 0.238, …Run Code Online (Sandbox Code Playgroud) 我有一个包含数字列表的向量。如何找到向量中缺失的数字?
例如:
sequence <- c(12:17,1:4,6:10,19)
Run Code Online (Sandbox Code Playgroud)
缺失的数字是 5、11 和 18。
我正在尝试keras-bert按照此处的说明进行安装:BERT from R。R本教程展示了如何使用加载和训练 BERT 模型Keras。
但是,当我在 Anaconda 提示符 (Windows) 中运行:
conda install keras-bert
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- keras-bert
Current channels:
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch …Run Code Online (Sandbox Code Playgroud)