Skip to content

Commit 70062bc

Browse files
committed
Merge branch 'master_community' into log_boosting_fn
2 parents 9e24912 + 13446b0 commit 70062bc

25 files changed

+530
-399
lines changed

API_CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ This is obsolete. Use getRegion('name') instead.
105105

106106
We also renamed the namespaces from `namespace nupic` to `namespace htm`.
107107

108+
* SpatialPooler: removed param `numActiveColumnsPerInhArea`, as replaced by `localAreaDensity` which has better properties
109+
(constant sparsity). PR #TODO
110+
108111

109112
## Python API Changes
110113

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22

3-
This file is no longer being updated.
4-
Instead see the [API_CHANGELOG](API_CHANGELOG.md).
3+
Also see [API_CHANGELOG](API_CHANGELOG.md).
4+
5+
## 2.0.0
6+
* changed repository name from nupic.core to htm.core
7+
* Added support for Visual Studio 2019
58

69
## 1.1.0
710

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The easiest way to contribute is to simply use this library and if you encounter
77

88
### Develop Nupic!
99
If you'd like to develop this library itself, we have put together a list of tasks which don't require extensive knowledge of this library but nonetheless are important and need help. Look for issues with the tag "newbie" which are a good starting point:
10-
* https://github.com/htm-community/nupic.cpp/labels/newbie
10+
* https://github.com/htm-community/htm.core/labels/newbie
1111

1212
### Discuss Nupic!
1313
We are open to new ideas and would be happy to discuss them. To start the conversation, open an issue and we can talk about it.

CommonCompilerConfig.cmake

+15-7
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ set(COMMON_OS_LIBS)
154154

155155
if(MSVC)
156156
# MS Visual C
157-
# on Windows using Visual Studio 2015, 2017 https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category
157+
# on Windows using Visual Studio 2015, 2017, 2019 https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category
158158
# /permissive- forces standards behavior. See https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017
159159
# /Zc:__cplusplus This is required to force MSVC to pay attention to the standard setting and sets __cplusplus.
160160
# NOTE: MSVC does not support C++11. But does support C++14 and C++17.
@@ -239,13 +239,22 @@ else()
239239

240240
#
241241
# Set linker (ld)
242-
# use ld.gold if available
242+
# These linkers are tried for faster linking performance
243+
# use ld.gold, or lld if available
243244
#
244-
execute_process(COMMAND ld.gold --version RESULT_VARIABLE EXIT_CODE)
245-
if(EXIT_CODE EQUAL 0)
245+
execute_process(COMMAND ld.gold --version RESULT_VARIABLE EXIT_CODE_GOLD)
246+
if(EXIT_CODE_GOLD EQUAL 0)
246247
message("Using ld.gold as LINKER.")
247248
set(CMAKE_LINKER "ld.gold")
249+
set(optimization_flags_cc ${optimization_flags_cc} -fuse-ld=gold)
248250
endif()
251+
execute_process(COMMAND ld.lld --version RESULT_VARIABLE EXIT_CODE_LLD)
252+
execute_process(COMMAND ld.lld-9 --version RESULT_VARIABLE EXIT_CODE_LLD9)
253+
if(EXIT_CODE_LLD EQUAL 0 OR EXIT_CODE_LLD9 EQUAL 0)
254+
message("Using ld.lld as LINKER.")
255+
set(CMAKE_LINKER "ld.lld")
256+
set(optimization_flags_cc ${optimization_flags_cc} -fuse-ld=lld)
257+
endif()
249258

250259

251260
#
@@ -344,11 +353,10 @@ else()
344353
set(optimization_flags_cc ${optimization_flags_cc} -march=native)
345354
endif()
346355
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND NOT MINGW)
347-
set(optimization_flags_cc ${optimization_flags_cc} -fuse-ld=gold)
348356
# NOTE -flto must go together in both cc and ld flags; also, it's presently incompatible
349357
# with the -g option in at least some GNU compilers (saw in `man gcc` on Ubuntu)
350-
set(optimization_flags_cc ${optimization_flags_cc} -fuse-linker-plugin -flto-report -flto) #TODO fix LTO for clang
351-
set(optimization_flags_lt ${optimization_flags_lt} -flto) #TODO LTO for clang too
358+
set(optimization_flags_cc ${optimization_flags_cc} -fuse-linker-plugin -flto-report -flto -fno-fat-lto-objects) #TODO fix LTO for clang
359+
set(optimization_flags_lt ${optimization_flags_lt} -flto -fno-fat-lto-objects) #TODO LTO for clang too
352360
endif()
353361

354362

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<img src="http://numenta.org/87b23beb8a4b7dea7d88099bfb28d182.svg" alt="NuPIC Logo" width=100/>
22

3-
# Community NuPIC.cpp repository (formerly [nupic.core](http://github.com/numenta/nupic.core))
3+
# htm.core
44

55
[![Linux/OSX Build Status](https://travis-ci.org/htm-community/htm.core.svg?branch=master)](https://travis-ci.org/htm-community/htm.core)
66
[![OSX CircleCI](https://circleci.com/gh/htm-community/htm.core/tree/master.svg?style=svg)](https://circleci.com/gh/htm-community/htm.core/tree/master)
77
[![Windows Build status](https://ci.appveyor.com/api/projects/status/59f87and1x0ugss9/branch/master?svg=true)](https://ci.appveyor.com/project/htm-community/nupic-cpp/branch/master)
88

9-
This fork is a community version of the [nupic.core](https://github.com/numenta/nupic.core) C++ repository with Python bindings.
9+
This is a Community Fork of the [nupic.core](https://github.com/numenta/nupic.core) C++ repository, with Python bindings.
1010

1111
## Project Goals
1212

13-
- Actively developed C++ core library for nupic.core (Numenta's repos are in maintenance mode only)
13+
- Actively developed C++ core library (Numenta's NuPIC repos are in maintenance mode only)
1414
- Clean, lean, optimized, and modern codebase
1515
- Stable and well tested code
1616
- Open and easier involvement of new ideas across HTM community (it's fun to contribute, we make master run stable, but are more open to experiments and larger revamps of the code if it proves useful).
@@ -42,11 +42,11 @@ in C++ library.
4242

4343
## Building from Source
4444

45-
Fork or download the HTM-Community Nupic.cpp repository from https://github.com/htm-community/nupic.cpp
45+
Fork or download the HTM-Community htm.core repository from https://github.com/htm-community/htm.core
4646

4747
## Prerequisites
4848

49-
- [CMake](http://www.cmake.org/)
49+
- [CMake](http://www.cmake.org/) Version 3.8 (3.14 for Visual Studio 2019)
5050
- [Python](https://python.org/downloads/)
5151
- Version 3.4+
5252
- Version 2.7
@@ -125,10 +125,11 @@ make -j install
125125

126126
* This will not build the Python interface.
127127

128-
## Simple Build On Windows (MS Visual Studio 2017)
128+
## Simple Build On Windows (MS Visual Studio 2017 or 2019)
129129

130130
After downloading the repository, do the following:
131131

132+
* NOTE: Visual Studio 2019 requires CMake version 3.14 or higher.
132133
* CD to the top of repository.
133134
* Double click on startupMSVC.bat
134135
- This will setup the build, create the solution file (build/scripts/htm.cpp.sln), and start MS Visual Studio.
@@ -161,12 +162,12 @@ docker build --build-arg arch=arm64 .
161162

162163
### Linux auto build @ TravisCI
163164

164-
* [Build](https://travis-ci.org/htm-community/nupic.cpp)
165+
* [Build](https://travis-ci.org/htm-community/htm.core)
165166
* [Config](./.travis.yml)
166167

167168
### Mac OS/X auto build @ CircleCI
168169

169-
* [Build](https://circleci.com/gh/htm-community/nupic.cpp/tree/master)
170+
* [Build](https://circleci.com/gh/htm-community/htm.core/tree/master)
170171
* [Config](./.circleci/config.yml)
171172
* Local Test Build: `circleci local execute --job build-and-test`
172173

@@ -179,7 +180,7 @@ docker build --build-arg arch=arm64 .
179180

180181
This uses Docker and QEMU to achieve an ARM64 build on CircleCI's x86 hardware.
181182

182-
* **TODO!** [Build]()
183+
* [Build](https://circleci.com/gh/htm-community/htm.core/tree/master)
183184
* [Config](./.circleci/config.yml)
184185
* Local Test Build: `circleci local execute --job arm64-build-test`
185186

RELEASE.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# Release Process
22

3-
1. Select a green build in Bamboo that has the changes that you want to release
4-
2. Ensure that this build has the correct version in the VERSION file
5-
3. Create a Bamboo release with version matching the VERSION file in the repo
6-
4. Deploy the release in Bamboo. This will:
7-
- Validate that the Bamboo release number matches the wheel versions.
8-
- Push the wheels to PyPI
9-
- Push the source archive to S3
10-
- Create a Github release
11-
- Tag the repo commit with the version
12-
- Bump the VERSION file to the next bugfix release number
3+
Not doing releases yet.
134

145
:-)

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.8.community0
1+
2.0.0

bindings/py/cpp_src/bindings/algorithms/py_Connections.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ R"(Returns pair of:
143143

144144
py_Connections.def("raisePermanencesToThreshold", &Connections::raisePermanencesToThreshold);
145145

146+
py_Connections.def("synapseCompetition", &Connections::synapseCompetition);
147+
146148
py_Connections.def("bumpSegment", &Connections::bumpSegment);
147149

148150
py_Connections.def("destroyMinPermanenceSynapses", &Connections::destroyMinPermanenceSynapses);

bindings/py/cpp_src/bindings/algorithms/py_SpatialPooler.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ using namespace htm;
5050
, Real
5151
, bool
5252
, Real
53-
, Int
5453
, UInt
5554
, Real
5655
, Real
@@ -112,22 +111,6 @@ Argument localAreaDensity The desired density of active columns within
112111
most N columns remain ON within a local inhibition area, where
113112
N = localAreaDensity * (total number of columns in inhibition
114113
area).
115-
If localAreaDensity is set to any value less than 0,
116-
output sparsity will be determined by the numActivePerInhArea.
117-
118-
Argument numActiveColumnsPerInhArea An alternate way to control the sparsity of
119-
active columns. When numActivePerInhArea > 0, the inhibition logic will insure that
120-
at most 'numActivePerInhArea' columns remain ON within a local
121-
inhibition area (the size of which is set by the internally
122-
calculated inhibitionRadius). When using this method, as columns
123-
learn and grow their effective receptive fields, the
124-
inhibitionRadius will grow, and hence the net density of the
125-
active columns will *decrease*. This is in contrast to the
126-
localAreaDensity method, which keeps the density of active
127-
columns the same regardless of the size of their receptive
128-
fields.
129-
If numActivePerInhArea is specified then
130-
localAreaDensity must be < 0, and vice versa.
131114
132115
Argument stimulusThreshold This is a number specifying the minimum
133116
number of synapses that must be active in order for a column to
@@ -188,7 +171,6 @@ Argument wrapAround boolean value that determines whether or not inputs
188171
, py::arg("potentialPct") = 0.5
189172
, py::arg("globalInhibition") = false
190173
, py::arg("localAreaDensity") = 0.02f
191-
, py::arg("numActiveColumnsPerInhArea") = -1
192174
, py::arg("stimulusThreshold") = 0
193175
, py::arg("synPermInactiveDec") = 0.01
194176
, py::arg("synPermActiveInc") = 0.1
@@ -212,8 +194,6 @@ Argument wrapAround boolean value that determines whether or not inputs
212194
py_SpatialPooler.def("getGlobalInhibition", &SpatialPooler::getGlobalInhibition);
213195
py_SpatialPooler.def("setGlobalInhibition", &SpatialPooler::setGlobalInhibition);
214196

215-
py_SpatialPooler.def("getNumActiveColumnsPerInhArea", &SpatialPooler::getNumActiveColumnsPerInhArea);
216-
py_SpatialPooler.def("setNumActiveColumnsPerInhArea", &SpatialPooler::setNumActiveColumnsPerInhArea);
217197
py_SpatialPooler.def("getLocalAreaDensity", &SpatialPooler::getLocalAreaDensity);
218198
py_SpatialPooler.def("setLocalAreaDensity", &SpatialPooler::setLocalAreaDensity);
219199
py_SpatialPooler.def("getStimulusThreshold", &SpatialPooler::getStimulusThreshold);

docs/synapse_competition.docx

181 KB
Binary file not shown.

py/htm/examples/hotgym.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'sdrc_alpha': 0.1,
2222
'sp': {'boostStrength': 3.0,
2323
'columnCount': 1638,
24-
'numActiveColumnsPerInhArea': 72,
24+
'localAreaDensity': 0.04395604395604396,
2525
'potentialPct': 0.85,
2626
'synPermActiveInc': 0.04,
2727
'synPermConnected': 0.13999999999999999,
@@ -63,8 +63,7 @@ def main(parameters=default_parameters, argv=None, verbose=True):
6363
potentialPct = spParams["potentialPct"],
6464
potentialRadius = encodingWidth,
6565
globalInhibition = True,
66-
localAreaDensity = -1,
67-
numActiveColumnsPerInhArea = spParams["numActiveColumnsPerInhArea"],
66+
localAreaDensity = spParams["localAreaDensity"],
6867
synPermInactiveDec = spParams["synPermInactiveDec"],
6968
synPermActiveInc = spParams["synPermActiveInc"],
7069
synPermConnected = spParams["synPermConnected"],

py/htm/examples/mnist.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import argparse
1919
import random
20-
import gzip
2120
import numpy as np
2221
import os
22+
import sys
2323

2424
from htm.bindings.algorithms import SpatialPooler, Classifier
2525
from htm.bindings.sdr import SDR, Metrics
@@ -36,7 +36,7 @@ def int32(b):
3636
return i
3737

3838
def load_labels(file_name):
39-
with gzip.open(file_name, 'rb') as f:
39+
with open(file_name, 'rb') as f:
4040
raw = f.read()
4141
assert(int32(raw[0:4]) == 2049) # Magic number
4242
labels = []
@@ -46,7 +46,7 @@ def load_labels(file_name):
4646
return labels
4747

4848
def load_images(file_name):
49-
with gzip.open(file_name, 'rb') as f:
49+
with open(file_name, 'rb') as f:
5050
raw = f.read()
5151
assert(int32(raw[0:4]) == 2051) # Magic number
5252
num_imgs = int32(raw[4:8])
@@ -67,32 +67,36 @@ def load_images(file_name):
6767
assert(len(raw) == data_start + img_size * num_imgs) # All data should be used.
6868
return imgs
6969

70-
train_labels = load_labels(os.path.join(path, 'train-labels-idx1-ubyte.gz'))
71-
train_images = load_images(os.path.join(path, 'train-images-idx3-ubyte.gz'))
72-
test_labels = load_labels(os.path.join(path, 't10k-labels-idx1-ubyte.gz'))
73-
test_images = load_images(os.path.join(path, 't10k-images-idx3-ubyte.gz'))
70+
train_labels = load_labels(os.path.join(path, 'train-labels-idx1-ubyte'))
71+
train_images = load_images(os.path.join(path, 'train-images-idx3-ubyte'))
72+
test_labels = load_labels(os.path.join(path, 't10k-labels-idx1-ubyte'))
73+
test_images = load_images(os.path.join(path, 't10k-images-idx3-ubyte'))
7474

7575
return train_labels, train_images, test_labels, test_images
7676

77-
77+
# These parameters can be improved using parameter optimization,
78+
# see py/htm/optimization/ae.py
79+
# For more explanation of relations between the parameters, see
80+
# src/examples/mnist/MNIST_CPP.cpp
7881
default_parameters = {
79-
'boostStrength': 7.80643753517375,
80-
'columnDimensions': (35415,1),
81-
'dutyCyclePeriod': 1321,
82-
'localAreaDensity': 0.05361688506086096,
83-
'minPctOverlapDutyCycle': 0.0016316043362658,
84-
'potentialPct': 0.06799785776775163,
85-
'stimulusThreshold': 8,
86-
'synPermActiveInc': 0.01455789388651146,
87-
'synPermConnected': 0.021649964738697944,
88-
'synPermInactiveDec': 0.006442691852205935
82+
'potentialRadius': 7,
83+
'boostStrength': 7.0,
84+
'columnDimensions': (28*28*8, 1),
85+
'dutyCyclePeriod': 1402,
86+
'localAreaDensity': 0.1,
87+
'minPctOverlapDutyCycle': 0.2,
88+
'potentialPct': 0.1,
89+
'stimulusThreshold': 6,
90+
'synPermActiveInc': 0.14,
91+
'synPermConnected': 0.5,
92+
'synPermInactiveDec': 0.02
8993
}
9094

9195

9296
def main(parameters=default_parameters, argv=None, verbose=True):
9397
parser = argparse.ArgumentParser()
9498
parser.add_argument('--data_dir', type=str,
95-
default = os.path.join( os.path.dirname(__file__), 'MNIST_data'))
99+
default = os.path.join( os.path.dirname(__file__), '..', '..', '..', 'build', 'ThirdParty', 'mnist_data', 'mnist-src'))
96100
args = parser.parse_args(args = argv)
97101

98102
# Load data.
@@ -107,11 +111,10 @@ def main(parameters=default_parameters, argv=None, verbose=True):
107111
sp = SpatialPooler(
108112
inputDimensions = enc.dimensions,
109113
columnDimensions = parameters['columnDimensions'],
110-
potentialRadius = 99999999,
114+
potentialRadius = parameters['potentialRadius'],
111115
potentialPct = parameters['potentialPct'],
112116
globalInhibition = True,
113117
localAreaDensity = parameters['localAreaDensity'],
114-
numActiveColumnsPerInhArea = -1,
115118
stimulusThreshold = int(round(parameters['stimulusThreshold'])),
116119
synPermInactiveDec = parameters['synPermInactiveDec'],
117120
synPermActiveInc = parameters['synPermActiveInc'],
@@ -143,10 +146,11 @@ def main(parameters=default_parameters, argv=None, verbose=True):
143146
sp.compute( enc, False, columns )
144147
if lbl == np.argmax( sdrc.infer( columns ) ):
145148
score += 1
149+
score = score / len(test_data)
146150

147-
print('Score:', 100 * score / len(test_data), '%')
148-
return score / len(test_data)
151+
print('Score:', 100 * score, '%')
152+
return score < 0.95
149153

150154

151155
if __name__ == '__main__':
152-
main()
156+
sys.exit( main() )

0 commit comments

Comments
 (0)