Skip to content

Commit

Permalink
Merge branch 'master' into remove_the_batch_suffix_from_examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Razdoburdin committed Aug 2, 2023
2 parents a8ec489 + 2a59f68 commit 34e606c
Show file tree
Hide file tree
Showing 57 changed files with 1,047 additions and 700 deletions.
2 changes: 1 addition & 1 deletion .ci/pipeline/build-and-test-lnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
displayName: 'System info'
- script: |
conda update -y -q conda
if [ $(echo $(PYTHON_VERSION) | grep '3.7') ] || [ $(echo $(PYTHON_VERSION) | grep '3.11') ]; then export DPCPP_PACKAGE="dpcpp-cpp-rt>=2023.1.0"; else export DPCPP_PACKAGE="dpctl>=0.14 dpcpp-cpp-rt>=2023.1.0"; fi
if [ $(echo $(PYTHON_VERSION) | grep '3.7') ] || [ $(echo $(PYTHON_VERSION) | grep '3.11') ]; then export DPCPP_PACKAGE="dpcpp-cpp-rt>=2023.2.0"; else export DPCPP_PACKAGE="dpctl>=0.14 dpcpp-cpp-rt>=2023.2.0"; fi
conda create -q -y -n CB -c conda-forge -c intel python=$(PYTHON_VERSION) dal-devel mpich pyyaml $DPCPP_PACKAGE
displayName: 'Conda create'
- script: |
Expand Down
2 changes: 1 addition & 1 deletion .ci/pipeline/build-and-test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
sudo chown -R $USER $CONDA
conda config --set always_yes yes --set changeps1 no
conda update -q conda
conda create -n CB -c conda-forge python=$(PYTHON_VERSION) dal=2023.0.1 dal-include=2023.0.1 mpich clang-format pyyaml
conda create -n CB -c conda-forge python=$(PYTHON_VERSION) dal-devel mpich clang-format pyyaml
displayName: Create Anaconda environment
- script: |
source activate CB
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/install_dpcpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo add-apt-repository -y "deb https://apt.repos.intel.com/oneapi all main"
sudo apt-get update
sudo apt-get install -y intel-dpcpp-cpp-compiler-2023.1.0
sudo apt-get install -y intel-dpcpp-cpp-compiler-2023.2.0
sudo bash -c 'echo libintelocl.so > /etc/OpenCL/vendors/intel-cpu.icd'
sudo mv -f /opt/intel/oneapi/compiler/latest/linux/lib/oclfpga /opt/intel/oneapi/compiler/latest/linux/lib/oclfpga_
12 changes: 6 additions & 6 deletions examples/daal4py/covariance_streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,17 +12,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py covariance example for streaming on shared memory systems

import daal4py as d4p

# let's use a generator for getting stream from file (defined in stream.py)
from stream import read_next

import daal4py as d4p


def main(readcsv=None, method='defaultDense'):
def main(readcsv=None, method="defaultDense"):
infile = "./data/batch/covcormoments_dense.csv"

# configure a covariance object
Expand All @@ -44,4 +44,4 @@ def main(readcsv=None, method='defaultDense'):
res = main()
print("Covariance matrix:\n", res.covariance)
print("Mean vector:\n", res.mean)
print('All looks good!')
print("All looks good!")
25 changes: 16 additions & 9 deletions examples/daal4py/dbscan_spmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,25 +12,26 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py DBSCAN example for distributed memory systems; SPMD mode
# run like this:
# mpirun -n 4 python ./dbscan_spmd.py

import daal4py as d4p
import numpy as np

import daal4py as d4p


def main(method='defaultDense'):
def main(method="defaultDense"):
infile = "./data/batch/dbscan_dense.csv"
epsilon = 0.04
minObservations = 45

# Load the data
data = np.loadtxt(infile, delimiter=',')
data = np.loadtxt(infile, delimiter=",")
rpp = int(data.shape[0] / d4p.num_procs())
data = data[rpp * d4p.my_procid(): rpp * d4p.my_procid() + rpp, :]
data = data[rpp * d4p.my_procid() : rpp * d4p.my_procid() + rpp, :]

# configure dbscan main object
algo = d4p.dbscan(minObservations=minObservations, epsilon=epsilon, distributed=True)
Expand All @@ -44,7 +45,13 @@ def main(method='defaultDense'):
# Initialize SPMD mode
d4p.daalinit()
result = main()
print("\nResults on node with id = ", d4p.my_procid(), " :\n",
"\nFirst 10 cluster assignments:\n", result.assignments[0:10],
"\nNumber of clusters:\n", result.nClusters)
print(
"\nResults on node with id = ",
d4p.my_procid(),
" :\n",
"\nFirst 10 cluster assignments:\n",
result.assignments[0:10],
"\nNumber of clusters:\n",
result.nClusters,
)
d4p.daalfini()
2 changes: 2 additions & 0 deletions examples/daal4py/decision_forest_classification_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
2 changes: 2 additions & 0 deletions examples/daal4py/decision_forest_regression_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
2 changes: 2 additions & 0 deletions examples/daal4py/decision_tree_classification_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
2 changes: 2 additions & 0 deletions examples/daal4py/decision_tree_regression_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
2 changes: 2 additions & 0 deletions examples/daal4py/gradient_boosted_classification_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
2 changes: 2 additions & 0 deletions examples/daal4py/gradient_boosted_regression_traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import daal4py as d4p

import daal4py as d4p


def printTree(nodes, values):
def printNodes(node_id, nodes, values, level):
Expand Down
15 changes: 8 additions & 7 deletions examples/daal4py/kmeans_spmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,29 +12,30 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py K-Means example for distributed memory systems; SPMD mode
# run like this:
# mpirun -n 4 python ./kmeans_spmd.py

import daal4py as d4p
from numpy import loadtxt

import daal4py as d4p


def main(method='plusPlusDense'):
def main(method="plusPlusDense"):
infile = "./data/distributed/kmeans_dense.csv"
nClusters = 10
maxIter = 25

# configure a kmeans-init
init_algo = d4p.kmeans_init(nClusters, method=method, distributed=True)
# Load the data
data = loadtxt(infile, delimiter=',')
data = loadtxt(infile, delimiter=",")
# now slice the data,
# it would have been better to read only what we need, of course...
rpp = int(data.shape[0] / d4p.num_procs())
data = data[rpp * d4p.my_procid(): rpp * d4p.my_procid() + rpp, :]
data = data[rpp * d4p.my_procid() : rpp * d4p.my_procid() + rpp, :]

# compute initial centroids
init_result = init_algo.compute(data)
Expand Down Expand Up @@ -78,5 +79,5 @@ def main(method='plusPlusDense'):
print("\nFirst 10 cluster assignments:\n", assignments[0:10])
print("\nFirst 10 dimensions of centroids:\n", result.centroids[:, 0:10])
print("\nObjective function value:\n", result.objectiveFunction)
print('All looks good!')
print("All looks good!")
d4p.daalfini()
30 changes: 18 additions & 12 deletions examples/daal4py/linear_regression_spmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,30 +12,32 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py Linear Regression example for distributed memory systems; SPMD mode
# run like this:
# mpirun -n 4 python ./linreg_spmd.py

import daal4py as d4p
from numpy import loadtxt

import daal4py as d4p

if __name__ == "__main__":
# Initialize SPMD mode
d4p.daalinit()

# Each process gets its own data
infile = "./data/distributed/linear_regression_train_" + \
str(d4p.my_procid() + 1) + ".csv"
infile = (
"./data/distributed/linear_regression_train_" + str(d4p.my_procid() + 1) + ".csv"
)

# Configure a Linear regression training object
train_algo = d4p.linear_regression_training(distributed=True)

# Read data. Let's have 10 independent,
# and 2 dependent variables (for each observation)
indep_data = loadtxt(infile, delimiter=',', usecols=range(10))
dep_data = loadtxt(infile, delimiter=',', usecols=range(10, 12))
indep_data = loadtxt(infile, delimiter=",", usecols=range(10))
dep_data = loadtxt(infile, delimiter=",", usecols=range(10, 12))
# Now train/compute, the result provides the model for prediction
train_result = train_algo.compute(indep_data, dep_data)

Expand All @@ -44,14 +46,18 @@
if d4p.my_procid() == 0:
predict_algo = d4p.linear_regression_prediction()
# read test data (with same #features)
pdata = loadtxt("./data/distributed/linear_regression_test.csv",
delimiter=',', usecols=range(10))
pdata = loadtxt(
"./data/distributed/linear_regression_test.csv",
delimiter=",",
usecols=range(10),
)
# now predict using the model from the training above
predict_result = d4p.linear_regression_prediction().compute(pdata,
train_result.model)
predict_result = d4p.linear_regression_prediction().compute(
pdata, train_result.model
)

# The prediction result provides prediction
assert predict_result.prediction.shape == (pdata.shape[0], dep_data.shape[1])

print('All looks good!')
print("All looks good!")
d4p.daalfini()
21 changes: 12 additions & 9 deletions examples/daal4py/linear_regression_streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,32 +12,35 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py Linear Regression example for streaming on shared memory systems

import daal4py as d4p
import numpy as np

import daal4py as d4p

# let's try to use pandas' fast csv reader
try:
import pandas

def read_csv(f, c, s=0, n=None, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None,
skiprows=s, nrows=n, dtype=t)
return pandas.read_csv(
f, usecols=c, delimiter=",", header=None, skiprows=s, nrows=n, dtype=t
)

except:
# fall back to numpy genfromtxt
def read_csv(f, c, s=0, n=np.iinfo(np.int64).max):
a = np.genfromtxt(f, usecols=c, delimiter=',', skip_header=s, max_rows=n)
a = np.genfromtxt(f, usecols=c, delimiter=",", skip_header=s, max_rows=n)
if a.shape[0] == 0:
raise Exception("done")
if a.ndim == 1:
return a[:, np.newaxis]
return a


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/linear_regression_train.csv"
testfile = "./data/batch/linear_regression_test.csv"

Expand Down Expand Up @@ -81,7 +84,7 @@ def main(readcsv=read_csv, method='defaultDense'):
print("\nLinear Regression coefficients:\n", train_result.model.Beta)
print(
"\nLinear Regression prediction results: (first 10 rows):\n",
predict_result.prediction[0:10]
predict_result.prediction[0:10],
)
print("\nGround truth (first 10 rows):\n", ptdata[0:10])
print('All looks good!')
print("All looks good!")
19 changes: 11 additions & 8 deletions examples/daal4py/low_order_moms_streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,32 +12,35 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py low order moments example for streaming on shared memory systems

import daal4py as d4p
import numpy as np

import daal4py as d4p

# let's try to use pandas' fast csv reader
try:
import pandas

def read_csv(f, c, s=0, n=None, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None,
skiprows=s, nrows=n, dtype=t)
return pandas.read_csv(
f, usecols=c, delimiter=",", header=None, skiprows=s, nrows=n, dtype=t
)

except:
# fall back to numpy genfromtxt
def read_csv(f, c, s=0, n=np.iinfo(np.int64).max):
a = np.genfromtxt(f, usecols=c, delimiter=',', skip_header=s, max_rows=n)
a = np.genfromtxt(f, usecols=c, delimiter=",", skip_header=s, max_rows=n)
if a.shape[0] == 0:
raise Exception("done")
if a.ndim == 1:
return a[:, np.newaxis]
return a


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
# read data from file
file = "./data/batch/covcormoments_dense.csv"

Expand Down Expand Up @@ -78,4 +81,4 @@ def main(readcsv=read_csv, method='defaultDense'):
print("\nVariance:\n", res.variance)
print("\nStandard deviation:\n", res.standardDeviation)
print("\nVariation:\n", res.variation)
print('All looks good!')
print("All looks good!")
Loading

0 comments on commit 34e606c

Please sign in to comment.