Learn R Programming

isotree (version 0.6.1-1)

isotree.is.same: Check if two Isolation Forest Models Share the Same C++ Object

Description

Checks if two isolation forest models, as produced by functions like isolation.forest, have a reference to the same underlying C++ object.

When this is the case, functions that produce in-place modifications, such as isotree.build.indexer, will produce changes in all of the R variables that share the same C++ object.

Two R variables will have the same C++ object when assigning one variable to another, but will have different C++ objects when these R objects are serialized and deserialized or when calling isotree.deep.copy.

Usage

isotree.is.same(obj1, obj2)

Value

A logical (boolean) value which will be `TRUE` when both models have a reference to the same C++ object, or `FALSE` otherwise.

Arguments

obj1

First model to compare (against `obj2`).

obj2

Second model to compare (against `obj1`).

See Also

isotree.deep.copy

Examples

Run this code
library(isotree)
data(mtcars)
model <- isolation.forest(mtcars, ntrees = 10, nthreads = 1, ndim = 1)

model_shallow_copy <- model
isotree.is.same(model, model_shallow_copy)

model_deep_copy <- isotree.deep.copy(model)
isotree.is.same(model, model_deep_copy)

isotree.add.tree(model_shallow_copy, mtcars)
length(isotree.get.num.nodes(model_shallow_copy)$total)
length(isotree.get.num.nodes(model)$total)
length(isotree.get.num.nodes(model_deep_copy)$total)

Run the code above in your browser using DataLab