Skip to content

Commit

Permalink
Update: 0.1.8-11.25.2023.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yibocat committed Nov 25, 2023
1 parent 7377549 commit a8e50ef
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
21 changes: 13 additions & 8 deletions mohupy/measure/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np


def choquet(e: (list, np.ndarray), func, *args, measurable_func=None, info=False):
def choquet(e: (list, np.ndarray), func, *args, measurable_func=None, info=False, summation=True):
"""
Choquet integral based on arbitrary fuzzy measures over a subset of a
fixed set.
Expand All @@ -31,6 +31,8 @@ def choquet(e: (list, np.ndarray), func, *args, measurable_func=None, info=False
The measurable function.
info: bool
Whether to print intermediate information.
summation: bool
summation or not
Returns
-------
Expand All @@ -49,13 +51,14 @@ def choquet(e: (list, np.ndarray), func, *args, measurable_func=None, info=False
'ERROR: The subset must be a list or numpy array.'
assert func is not None, \
'ERROR: The function must not be None.'
RI = np.asarray(*args) if measurable_func is None else measurable_func(*args)
RI = (np.asarray(*args) # When no args are set, use the fuzzy measure e directly.
if measurable_func is None else measurable_func(*args)) if len(args) > 0 else np.asarray(e)
index = np.argsort(-RI) # fuzzy measure subscripts in descending sort
sub = np.sort(e)[::-1]

p = []
for i in range(len(index)):
p.append(func(sub[:i + 1], *args) - func(sub[:i], *args))
p.append(func(sub[:i + 1], sub) - func(sub[:i], sub))
p = np.asarray(p)

# Arrange the derivatives of the fuzzy measure set function in descending order
Expand All @@ -77,7 +80,7 @@ def choquet(e: (list, np.ndarray), func, *args, measurable_func=None, info=False
integral = np.array([])
for i in range(len(index)):
integral = np.append(integral, fz[i] * p[i])
return sum(integral)
return sum(integral) if summation else integral


def sugeno(e: (list, np.ndarray), func, *args, measurable_func=None):
Expand Down Expand Up @@ -117,12 +120,13 @@ def sugeno(e: (list, np.ndarray), func, *args, measurable_func=None):
'ERROR: The subset must be a list or numpy array.'
assert func is not None, \
'ERROR: The function must not be None.'
RI = np.asarray(*args) if measurable_func is None else measurable_func(*args)
RI = (np.asarray(*args) # When no args are set, use the fuzzy measure e directly.
if measurable_func is None else measurable_func(*args)) if len(args) > 0 else np.asarray(e)

sub = np.sort(e)
res = np.array([])
for i in range(len(sub)):
res = np.append(res, min(sub[i], func(sub[i:], RI)))
res = np.append(res, min(sub[i], func(sub[i:], sub)))
return np.max(res)


Expand Down Expand Up @@ -162,10 +166,11 @@ def shilkret(e: (list or np.ndarray), func, *args, measurable_func=None):
'ERROR: The subset must be a list or numpy array.'
assert func is not None, \
'ERROR: The function must not be None.'
RI = np.asarray(*args) if measurable_func is None else measurable_func(*args)
RI = (np.asarray(*args) # When no args are set, use the fuzzy measure e directly.
if measurable_func is None else measurable_func(*args)) if len(args) > 0 else np.asarray(e)

sub = np.sort(e)
res = np.array([])
for i in range(len(sub)):
res = np.append(res, sub[i] * func(sub[i:], RI))
res = np.append(res, sub[i] * func(sub[i:], sub))
return np.max(res)
100 changes: 100 additions & 0 deletions test/test6.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import mohupy as mp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"s = [0.4, 0.25, 0.37, 0.2]\n",
"t = [0.49, 0.67,0.13, 0.55 ,0.89, 0.33, 0.41]"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"def f(*args):\n",
" return True if len(args)!=0 else False"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"f(0.6,0.4)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": "array([0. , 0. , 0. , 0.06014714, 0.09482835,\n 0.20423983, 0.356 ])"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mp.integral.choquet(s, mp.lambda_meas,t, summation=False)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
4 changes: 4 additions & 0 deletions update.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# UPDATE LOG

------
### version: 0.1.8-11.25.2023
1. 修复了 Choquet integral 无法正常计算的 bug

------
### version: 0.1.8-11.24.2023
修复了一些 bugs
Expand Down

0 comments on commit a8e50ef

Please sign in to comment.