交叉递归图计算迭代的问题

时间:2019-01-23 15:09:16

标签: python function loops iteration

我想请你帮忙

我有一个数据框,其中包含来自不同受试者(eda1,eda2,eda3等)的皮肤电活动(EDA)变量。 我手动计算主题的Cross Recurrence Quantification Plot和复发率作为同步的量度。

<!doctype html>
<html lang="en">
  <head>
    <!-- link to css -->
    <link rel="stylesheet" href="style.css">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

    <title>Notebook</title>
  </head>
  <body>
    
    
    <div class="container min-vh-100 d-flex flex-column" id="container">

      <!-- header -->
      <div class="row align-items-start bg-info container" id="header">
        <div class="col text-center">
            <button type="button" class="btn" id="cancel">&#10007;</button>
            <button type="button" class="btn" id="back">&#8617;</button>
        </div>
        <div class="col text-center">
          <h4 id="title">Notebook</h4>
        </div>
        <div class="col text-center">
            <button type="button" class="btn" id="submit">&#10004;</button>
        </div>
      </div>
      
      <br />

      <!-- Screen list show -->
        <div class="row" id="screen">
            <div class="col-12">
                <ul id="list">
                  
                </ul>
            </div>
        </div>

        <!-- Note show -->
      <div class="row" id="fullnote">
            <div class="col-12">
              <p id="text">
              </p>
            </div>
        </div>

      <!-- input for note title -->
      <div class="row" id="input-title">
        <div class="col">
            <input type="text" maxlength="20" class="form-control" placeholder="Note title" value="" id="note-title">
        </div>
      </div>

      <br />

      <!-- textarea for writing note -->
      <div class="row flex-grow-1">
        <div class="col" id="main">
            <textarea class="form-control textarea h-100" value="" placeholder="write note" id="note"></textarea>
        </div>
      </div>

      
      <!-- footer -->
      <div class="row align-items-end container" id="footer">
        <div class="col d-flex justify-content-start" style="padding: 10px; padding-left: 25px;">
          <button id="add" class="btn btn-info rounded-circle"><h4 style="padding: 0px; margin: 0px;">&#x2b;</h4></button>
          <button id="delete" class="btn btn-info rounded-circle">&#128465;</button>
        </div>
      </div>
    
    </div>

    
    <script src="script.js"></script>
  </body>
</html>

但是我需要针对所有受试者(eda1raw1,eda1raw2,... eda1rawN)的复发率(缩写:RR)的自动函数或迭代函数。 我有许多EDA变量,我不想写:

from pyunicorn.timeseries import CrossRecurrencePlot, RecurrencePlot
from nolitsa import data, dimension, delay
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy import stats
import pylab

eda1 = data['eda1raw'] 
eda2 = data['eda2raw']

eda1z = stats.zscore(eda1)
eda2z = stats.zscore(eda2)

DIM = 5  
TAU = 10  
METRIC = "supremum" 
THRESHOLD=0.5 
crp = CrossRecurrencePlot(eda1z, eda2z, dim=DIM, tau=TAU, metric=METRIC, normalize=False, threshold=THRESHOLD) 
print "Recurrence rate - RReda1vs2z:", crp.recurrence_rate()

最终结果应为所有受试者的EDA复发率矩阵: enter image description here

我尝试了一些事情:

crp = CrossRecurrencePlot(eda1z, eda2z, dim=DIM, tau=TAU, metric=METRIC, normalize=False, threshold=THRESHOLD) 
crp1 = CrossRecurrencePlot(eda3z, eda4z, dim=DIM, tau=TAU, metric=METRIC, normalize=False, threshold=THRESHOLD) 
...

然后转置到数组。

1 个答案:

答案 0 :(得分:0)

MikulášMuroň的解决方案:

# Save data to list
input_data = [xd, yd, cd, dd, ed, fd, gd, hd, iid, jd, kd, ld, md, nd, od, pd]
# transform to np.array
input_data_numpy_array = [np.array(x) for x in input_data]
# counting zscore
zscore_data = [stats.zscore(x) for x in input_data_numpy_array]
# counting phasic diemnsion of EDA
eda_data = [cvxEDA(x, delta=1) for x in zscore_data]

# processing data - actual and next element
for eda_data1,eda_data2 in zip(eda_data, eda_data[1:]):
    crp = CrossRecurrencePlot(eda_data1.next(), eda_data2.next(), dim=DIM, tau=TAU, metric=METRIC, normalize=False, threshold=THRESHOLD)
    pylab.imshow(crp.recurrence_matrix())
    pylab.xlabel("$n$")
    pylab.ylabel("$n$")
    pylab.show()

    print("Recurrence rate:", crp.recurrence_rate())