{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "collapsed": true,
        "pycharm": {
          "is_executing": false
        }
      },
      "outputs": [
        {
          "name": "stdout",
          "text": [
            "a\nab\nabc\nb\nbc\nbcd\nc\ncd\ncde\nd\nde\ndef\ne\nef\nf\n"
          ],
          "output_type": "stream"
        }
      ],
      "source": "original_seq \u003d [\u0027a\u0027,\u0027b\u0027,\u0027c\u0027,\u0027d\u0027,\u0027e\u0027,\u0027f\u0027]\nmin_len \u003d 1\nmax_len \u003d 3\n\n\ncontig_seqs \u003d list()\n\nfor st in range(len(original_seq)):\n    min_fin_index \u003d st + min_len\n    max_fin_index \u003d min(st + max_len, len(original_seq)) + 1\n\n    for fin in range(min_fin_index, max_fin_index):\n        seq \u003d original_seq[st:fin]\n        contig_seqs.append(seq)\n\nfor cs in contig_seqs:\n    print(\u0027\u0027.join(cs))\n"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "outputs": [],
      "source": "from scipy import stats\nimport heapq # to extract n largest values with nlargest()\n\n# PARAMS\n\nseq \u003d [\u0027a\u0027,\u0027b\u0027,\u0027c\u0027,\u0027d\u0027,\u0027e\u0027,\u0027f\u0027,\u0027e\u0027] # trials\nN \u003d 2 # N as in N-Back\n\n\ntrials \u003d len(seq)\n\ndef count_targets_and_lures():\n    # the first trials are distractors\n    mask \u003d \u0027D\u0027 * N\n    for index in range(N, trials):\n        if seq[index] \u003d\u003d seq[index - N]:\n            mask +\u003d \u0027T\u0027\n        elif seq[index] in seq[index - N - 1:index - N + 1]:\n            mask +\u003d \u0027L\u0027\n        else:\n            mask +\u003d \u0027D\u0027\n    return mask.count(\u0027T\u0027), mask.count(\u0027L\u0027)\n\n\ntargets,lures \u003d count_targets_and_lures()\ntargets_norm \u003d stats.norm(targets, 0.5)\nskewness_norm \u003d stats.norm(0, 0.5)\n\ndef skewness_cost(choices):\n    even_ratio \u003d len(seq) / len(choices)\n    costs \u003d {c: abs(seq.count(c) - even_ratio) for c in choices}\n    max_deviation_from_even_dist \u003d max(list(costs.values()))\n    cost \u003d 1.0 - (skewness_norm.pdf(max_deviation_from_even_dist) / skewness_norm.pdf(0))\n    return cost\n\n\n\ndef lures_ratio_cost():\n    return 1.0 - targets_norm.pdf(targets)\n\n\ndef targets_ratio_cost():\n    return 1.0 - targets_norm.pdf(targets)\n\ndef ralph2014_skewness(choices):\n    freqs \u003d [float(seq.count(c)) for c in choices]\n    ralph_skewed \u003d sum(heapq.nlargest(int(len(choices) / 2), freqs)) \u003e (trials * 2 / 3)\n    return ralph_skewed",
      "metadata": {
        "pycharm": {
          "metadata": false,
          "name": "#%%\n"
        }
      }
    }
  ],
  "metadata": {
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 2
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython2",
      "version": "2.7.6"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}