AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

computeDegreeOfMembership

该函数属于Yuka js库的FuzzySet模块,用于计算某个元素在模糊集中的隶属度。

语法

computeDegreeOfMembership(element);

参数

  • element:要计算隶属度的元素,类型为任意值。

返回值

该函数返回值的类型为数字,表示输入元素在模糊集中的隶属度。

实现

该函数基于Triangular Fuzzy Number(三角模糊数)的概念,使用以下公式计算输入元素在模糊集中的隶属度:

membershipDegree = max(0, min((x - a) / (b - a), (c - x) / (c - b)))

其中,abc是模糊集的三个点,x是要计算隶属度的元素。

示例

const fuzzySet = new FuzzySet([1, 2, 3]);
const membershipDegree = fuzzySet.computeDegreeOfMembership(2.5);
console.log(membershipDegree); // 输出: 0.5

上面示例中,创建了一个包含[1, 2, 3]三个元素的模糊集,然后计算元素2.5在该模糊集中的隶属度。结果为0.5,表示元素2.5在该模糊集中隶属度为50%