{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nSome utilities to create gorup lasso coefficients.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\n\ndef generate_group_lasso_coefficients(\n    group_sizes, inclusion_probability=0.5, coeff_std=1\n):\n    coefficients = []\n    for group_size in group_sizes:\n        coefficients_ = np.random.randn(group_size, 1) * coeff_std\n        coefficients_ *= np.random.uniform(0, 1) < inclusion_probability\n        coefficients.append(coefficients_)\n\n    return np.concatenate(coefficients, axis=0)\n\n\ndef get_groups_from_group_sizes(group_sizes):\n    groups_indices = (0, *np.cumsum(group_sizes))\n    groups = np.zeros(groups_indices[-1])\n    # groups = [None] * len(group_sizes)\n\n    for i, (start, stop) in enumerate(\n        zip(groups_indices[:-1], groups_indices[1:])\n    ):\n        groups[start:stop] = i\n        # groups[i] = (start, stop)\n    return groups"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.4"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}