Commit Graph

26 Commits

Author SHA1 Message Date
Thomas J. Fan 5572a342bb
MNT Replace PriorityHeap with cpp heap methods in trees (#22630) 2022-03-03 10:32:44 +01:00
Thomas J. Fan 70eebb992e
MNT Use C++ stack instead of implementing our own in trees (#22328) 2022-02-25 17:54:54 +01:00
Jérémie du Boisberranger 1f8825c8dd
MNT Centralize common cython compiler directives (#21512) 2021-11-03 13:26:23 +01:00
Thomas J Fan 581b0e1d73 MAINT Fix GCC warnings from Cython (#14077) 2019-07-01 18:55:29 +02:00
Thomas J Fan 5f0263fe7f BLD Fixes Cython cimport errors (#13754) 2019-05-01 16:58:48 +10:00
Aditya Vyas 301076e77b MAINT Replace absolute imports with relative imports (#13653) 2019-04-17 12:45:14 -04:00
jeremiedbb cad0fb434f MNT Use a common language_level cython directive (#13630) 2019-04-13 07:30:18 +02:00
Clément Doumouro 01bc8b18ac FIX non deterministic behavior in SGD (#13422) 2019-04-04 21:31:09 +11:00
Roman Yurchak 49570484db MAINT Use cython language_level=3 directive (#12873) 2019-02-28 18:45:15 +01:00
TakingItCasual 1e052e9da9 Converting http to https (2)... (#12292) 2018-10-04 23:06:14 +02:00
andreh7 485926e352 DOC docstring of rand_int value range (#8777) 2017-04-22 22:47:55 +10:00
(Venkat) Raghav (Rajagopalan) 4907029b1d [MRG+3] FIX Memory leak in MAE; Use safe_realloc; Acquire GIL only when raising; Propagate all errors to python interpreter level (#7811) (#8002)
* FIX MAE reg. criterion: Use safe_realloc to avoid memory leak

* Release GIL in safe_realloc and clean up scaffolding

* As gil is released in safe_realloc, no need of a with gil block

* Use except * to propagate error in all cdef functions

* Don't use except * for functions that return python objects

* Don't use except * for the comparison function passed to qsort

* Omissions and Errors

* Use safe_realloc now that gil is released there

* Fix realloc size

* Acquire GIL only if we need to raise

* Use except * more judiciously; Release gil only when raising; Add comments to clarify

* Actually that was unneeded; realloc will also allocate for the first time

* StackRecord*, PriorityHeapRecord* to fused type realloc_ptr; Use safe_realloc

* Use except -1 to propagate exceptions. This should avoid overheads

* Fix docstrings and add return 0 to reset methods

* TYPO

* REVIEW Remove redundant MemoryError raising calls
2017-01-19 00:58:16 +01:00
Nelson Liu f95e5b1a0d [MRG + 1] MAINT Move heapify_up/heapify_down into PriorityHeap as class methods + COSMITs (#7034)
* RFC: move heap methods to class and remove trailing spaces

* spurious comment to force recythonization of boosting

* [ci skip] remove spurious comment

* remove trailing whitespace on line

* style: fix trailing whitespace in _criterion.pxd

* add spurious comments to try to force recythonizing

* remove changes for recythonization
2016-12-27 04:29:39 +01:00
Ibraim Ganiev 74e4c422bd FIX #6420: Cloning decision tree estimators breaks criterion objects (#7680) 2016-10-20 10:10:50 +11:00
Nelson Liu c84ff5e351 [MRG+3] Add mean absolute error splitting criterion to DecisionTreeRegressor (#6667)
* feature: add initial node_value method

* testing code for node_impurity and node_value

This code runs into 'Bus Error: 10' at node_value final assignment.

* fix: node_value now correctly calculating weighted median for sorted data.

Still need to change the code to work with unsorted data.

* fix: node_value now correctly calculates median regardless of initial order

* fix: correct bug in calculating median when taking midpoint is necessary

* feature: add initial version of children_impurity

* feature: refactor median calculation into one function

* fix: fix use of DOUBLE_t vs double

* feature: move helper functions to _utils.pyx, fix mismatched pointer type

* fix: fix some bugs in children_impurity method

* push a debug version to try to solve segfault

* push latest changes, segfault probably happening bc of something in _utils.pyx

* fix: fix segfault in median calculation and remove excessive logging

* chore: revert some misc spacing changes I accidentally made

* chore: one last spacing fix in _splitter.pyx

* feature: don't calculate weighted median if no weights are passed in

* remove extraneous logging statement

* fix: fix children impurity calculation

* fix: fix bug with children impurity not being initally set to 0

* fix: hacky fix for a float accuracy error

* fix: incorrect type cast in median array generation for node_impurity

* slightly tweak node_impurity function

* fix: be more explicit with casts

* feature: revert cosmetic changes and free temporary arrays

* fix: only free weight array in median calcuation if it was created

* style: remove extraneous newline / trigger CI build

* style: remove extraneous 0 from range

* feature: save sorts within a node to speed it up

* fix: move parts of dealloc to regression criterion

* chore: add comment to splitter to try to force recythonizing

* chore: add comment to _tree.pyx to try to force recythonizing

* chore: add empty comment to gradient boosting to force recythonizing

* fix: fix bug in weighted median

* try moving sorted values to a class variable

* feature: refactor criterion to sort once initially, then draw all samples from this sorted data

* style: remove extraneous parens from if condition

* implement median-heap method for calculating impurity

* style: remove extra line

* style: fix inadvertent cosmetic changes; i'll address some of these in a separate PR

* feature: change minmaxheap to internally use sorted arrays

* refactored MAE and push to share work

* fix errors wrt median insertion case

* spurious comment to force recythonization

* general code cleanup

* fix typo in _tree.pyx

* removed some extraneous comments

* [ci skip] remove earlier microchanges

* [ci skip] remove change to priorityheap

* [ci skip] fix indentation

* [ci skip] fix class-specific issues with heaps

* [ci skip] restore a newline

* [ci skip] remove microchange to refactor later

* reword a comment

* remove heapify methods from queue class

* doc: update docstrings for dt, rf, and et regressors

* doc: revert incorrect spacing to shorten diff

* convert get_median to return value directly

* [ci skip] remove accidental whitespace

* remove extraneous unpacking of values

* style: misc changes to identifiers

* add docstrings and more informative variable identifiers

* [ci skip] add trivial comments to recythonize

* remove trivial comments for recythonizing

* force recythonization for real this time

* remove trivial comments for recythonization

* rfc: harmonize arg. names and remove unnecessary checks

* convert allocations to safe_realloc

* fix bug in weighted case and add tests for MAE

* change all medians to DOUBLE_t

* add loginc allocate mediancalculators once, and reset otherwise

* misc style fixes

* modify cinit of regressioncriterion to take n_samples

* add MAE formula and force rebuild bc. travis was down

* add criterion parameter to gradient boosting and add forest tests

* add entries to what's new
2016-07-25 08:44:59 +02:00
Nelson Liu d2aaf0f4bb doc: fix spellings of 'license' 2016-03-31 17:25:31 -07:00
Jacob Schreiber 5978c0bbdf ENH split _tree.pyx into several files 2015-09-09 11:28:24 +02:00
Arnaud Joly ce8b214154 MAINT reduce amount of boiler code using standard C operations 2014-06-19 20:13:59 +02:00
Gilles Louppe da95ad8a65 FIX: Set correct impurity values in BestFirstBuilder 2014-04-10 20:27:37 +02:00
Arnaud Joly 2c82c8adf0 FIX tons of flake8 2014-03-20 14:20:35 +01:00
Arnaud Joly abaf100a65 WIP add n_constant_features argument 2014-03-10 12:15:58 +01:00
Lars Buitinck 7fc52ffdb4 BUG fix unchecked mallocs in trees
All mallocs should be checked now. Some notes for the next person to touch
this code, or do anything with malloc in Cython code:

* with gil: raise MemoryError() didn't work as expected, as a surrounding
  nogil block catches and logs the exception, then proceeds as if nothing
  happened.
* There were several opportunities for double free in the code. This is
  handled by letting the destructor handle the freeing.
* Similarly, constructors failed to set pointers to NULL so __dealloc__
  would try to free unitialized pointers.
* Out of memory might leave trees in an inconsistent state, but will not
  cause a double free. A subsequent successful fit should produce a
  consistent state, although I didn't test this.
* Replaced a free/calloc with a realloc; realloc(NULL, n) = malloc(n).
* free(NULL) is a harmless no-op per ISO C89.

Also performed an optimization: the pre-sort splitter was using size_t for
an array of booleans. unsigned char is faster and smaller.

Finally, fixed some cosmetic issues (long lines).
2014-01-11 15:44:44 +01:00
Peter Prettenhofer dd680d6a2f malloc / realloc checks
correct rc values
2014-01-06 13:56:23 +01:00
Gilles Louppe ce0d52ea05 COSMITS + FIX to impurity_improvement 2013-11-29 14:02:21 +01:00
Gilles Louppe fbab2cd5e2 COSMIT + FIX in _utils.pyx 2013-11-29 11:15:59 +01:00
Peter Prettenhofer 635505e544 moved data structures (Stack + Heap) to _utils
use impurity_improvement for choosing best split
2013-11-22 15:33:59 +01:00