Skip to content

Commit

Permalink
Corrected HDBSCAN cache and uniform weights init
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoBobadilla committed Dec 20, 2020
1 parent 888cb90 commit 230dd1b
Show file tree
Hide file tree
Showing 14 changed files with 791 additions and 589 deletions.
74 changes: 41 additions & 33 deletions examples/CIDIE COVID features.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, '../')"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -19,6 +9,8 @@
"import json\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.image as mpimg\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from scipy.spatial.distance import cdist\n",
"from neural_map import NeuralMap, _plot"
Expand All @@ -30,6 +22,7 @@
"metadata": {},
"outputs": [],
"source": [
"# cargar los conjuntos de datos\n",
"train_features = np.load('datasets/train_features.npy')\n",
"train_labels = np.load('datasets/train_labels.npy')\n",
"test_features = np.load('datasets/test_features.npy')\n",
Expand All @@ -38,12 +31,43 @@
"train_features.shape, train_labels.shape, test_features.shape, test_labels.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# '01a4059c-22f7-4f51-8a27-50aff0b3aeb3.jpg': 5931,\n",
"# '01cc7c75-4498-43ab-b650-5553d0507f76.jpg': 5936,\n",
"# '042bde1a-88c1-4ae5-af0c-1a409e1e09ee.jpg': 5952,\n",
"# 'lancet-case2.png': 41,\n",
"# 'streptococcus-pneumoniae-pneumonia-1.jpeg': 10\n",
"\n",
"images_indices = {\n",
" 'auntminnie-a-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg': 35,\n",
" 'nejmoa2001191_f3-PA.jpeg': 46,\n",
" 'SARS-10.1148rg.242035193-g04mr34g0-Fig8a-day0.jpeg': 0,\n",
" 'SARS-10.1148rg.242035193-g04mr34g0-Fig8b-day5.jpeg': 1,\n",
"}\n",
"\n",
"for image_name, index in images_indices.items():\n",
" img = mpimg.imread('datasets/train_images/' + image_name)\n",
" imgplot = plt.imshow(img, cmap='Greys_r')\n",
" plt.show()\n",
" print(train_features[index])\n",
" print('\\n')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# escalar los valores al rango [0, 1]\n",
"\n",
"scaler = MinMaxScaler()\n",
"\n",
"s_train_features = scaler.fit_transform(train_features)\n",
Expand All @@ -58,12 +82,14 @@
"metadata": {},
"outputs": [],
"source": [
"# cargar la instancia de NeuralMap cargada\n",
"dictionary = {}\n",
"\n",
"with open('datasets/features_training_correlation_10.json') as json_file: \n",
" dictionary = json.load(json_file)\n",
" dictionary['relative_positions'] = np.array(dictionary['relative_positions'])\n",
" dictionary['weights'] = np.array(dictionary['weights'])\n",
" del dictionary['seed']\n",
" \n",
"nm = NeuralMap(**dictionary)"
]
Expand All @@ -74,25 +100,7 @@
"metadata": {},
"outputs": [],
"source": [
"nm.plot_unified_distance_matrix(detailed=True, borders=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nm.plot_analysis(data=s_train_features)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nm.plot_analysis(data=s_test_features)"
"nm.plot_unified_distance_matrix(detailed=True, borders=True, size=13)"
]
},
{
Expand All @@ -101,7 +109,7 @@
"metadata": {},
"outputs": [],
"source": [
"nm.plot_labels(data=s_train_features, labels=train_labels)"
"nm.plot_analysis(data=s_train_features, attached_values=train_labels, size=13, title='Distribución de las clases de radiografías (conjunto de datos de entrenamiento)')"
]
},
{
Expand All @@ -110,7 +118,7 @@
"metadata": {},
"outputs": [],
"source": [
"nm.plot_labels(data=s_test_features, labels=test_labels)"
"nm.plot_analysis(data=s_test_features, attached_values=test_labels, size=13, title='Distribución de las clases de radiografías (conjunto de datos de prueba)')"
]
},
{
Expand Down Expand Up @@ -138,7 +146,7 @@
"# 3) mostramos una imagen y la otra al lado.\n",
"# Un ejemplo simple es, hacer esos pasos con una imagen de entrenamiento y recuerar la clase de la misma.\n",
"\n",
"selected_feature_index = 412\n",
"selected_feature_index = 413\n",
"\n",
"if not ('mapped_train_features_indices' in vars() or 'mapped_train_features_indices' in globals()):\n",
" mapped_train_features_indices = nm.map_attachments(s_train_features, np.array(range(s_train_features.shape[0])))\n",
Expand Down Expand Up @@ -178,4 +186,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Loading

0 comments on commit 230dd1b

Please sign in to comment.