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

defuzzifyCentroid

简介

defuzzifyCentroid是Yuka js库中FuzzyVariable类的一个方法,用于计算模糊变量的模糊值的中心。

用法

该方法用于计算模糊变量的模糊值的实际值。通常来说,模糊变量映射到实际值时需要用到一个没有歧义的确定值,而defuzzifyCentroid方法正是为此而设计的。

以下是一个示例:

let temperature = new FuzzyVariable();

// 将一些模糊值添加到模糊变量
let 冷 = temperature.addLeftShoulderSet('冷', -10, 10, 20);
let 适宜 = temperature.addTriangularSet('适宜', 10, 20, 30);
let 热 = temperature.addRightShoulderSet('热', 20, 30, 40);

// 假设有一个模糊值为(0.5, 适宜)
let fuzzyValue = new FuzzyValue(适宜, 0.5);

// 计算此模糊值的实际值
let actualValue = temperature.defuzzifyCentroid(fuzzyValue);
console.log(actualValue); // 输出:20

实现

defuzzifyCentroid方法的实现基于模糊函数的中心原理。简单来说,它会先计算模糊集合的中心点,然后以此点作为模糊值的实际值。

以下是该方法的实现代码:

defuzzifyCentroid(fuzzyValue) {
  let set = fuzzyValue.set;
  let totalArea = 0;
  let sumOfProducts = 0;

  for (let i = 0; i <= set.resolution; i++) {
    let x = set.start + i * set.range / set.resolution;
    let y = set.getValueAt(x);
    totalArea += y;
    sumOfProducts += x * y;
  }

  if (totalArea === 0) {
    return NaN;
  }

  return sumOfProducts / totalArea;
}

参数

  • fuzzyValue: 需要计算实际值的模糊值。它应该是一个FuzzyValue对象。

返回值

  • 模糊值的实际值。如果计算过程中出现了问题,将返回NaN

参考资料