如何在约束下以图形方式定义参数值?

发布于 2024-12-11 17:56:07 字数 901 浏览 1 评论 0原文

我试图弄清楚是否可以实现以下 Mathematica 接口。

我想在 Mathematica 中创建一个界面,用户可以在受约束的情况下以图形方式和交互方式定义任意数量的数值参数。

问题中的参数是数字权重[0,1],每个权重都与相应的标准相关联,并且限制为总和为一。显然,这个约束导致了与每个标准相关的权重的权衡,我想通过沿着下面的线绘制一个交互式图(不幸的是,在 Excel 中制作),以图形方式使这种权衡变​​得明显:

示例图形权重定义

在这个例子中,有 6 个标准,但我想将其概括为任意数字(例如 2 到 7 之间)。

该界面的工作原理是沿着相应的轴拖动每个多边形顶点(对应于特定的权重),并让其他顶点均匀调整,使它们的总和始终为 1。

然后返回数值以用于后续计算。

我环顾四周,似乎找不到有同样问题的人(搜索查询的定义可能并不简单)。

我在 Mathematica 的示例中发现的最接近的东西是定位器窗格的以下应用,其中允许在正方形上移动 3 个点并返回它们的位置:

DynamicModule[{pt = {{1, 1} /2, {-1, 1}/2, {1, -1}/2}}, {LocatorPane[ 动态[pt],图形[{灰色,磁盘[]}]],动态[pt]}]

I'm trying to figure out whether it's possible to implement the following Mathematica interface.

I would like to create an interface in Mathematica whereby the user would be able to define graphically and interactively an arbitrary number of numerical parameters, subject to a constraint.

The parameters in questions are numerical weights [0,1], each associated to a corresponding criterion and constrained to summing to one. Obvously, this constraint induces a trade-off to the weights that can be associated to each criterion and I wanted to make such trade-off evident graphically, by having an interactive plot along the line of what follows (made in Excel, unfortunately):

Example of graphical weight definition

In this example, there are 6 criteria, but I would like to generalize that to an arbitrary number (between 2 and 7, for instance).

The interface would work by dragging each of the polygon vertices (corresponding to a specific weight) along the corresponding axis, and having the others adjust uniformely so that they always sum to 1.

The numerical values would then be returned to be used in subsequent computations.

I have looked around and do not seem to be able to find someone who had the same problem (the definition of the search queries is non-trivial, probably).

The closest thing I've found among Mathematica's examples is the following application of the locator pane, where 3 points are allowed to be moved on a square and their position is returned:

DynamicModule[{pt = {{1, 1}/2, {-1, 1}/2, {1, -1}/2}}, {LocatorPane[
Dynamic[pt], Graphics[{Gray, Disk[]}]], Dynamic[pt]}]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-12-18 17:56:07

也许是这样的:

n = 6;
posText[x_List] := Text[Round[Norm@#/Total@(Norm /@ x), .01], 1.3 #, 
                        Background -> LightRed] & /@ x;
rot = RotationMatrix[Pi/15];
DynamicModule[{
  pt = pti = {Re@#, Im@#} &@(E^(2 I Pi #/n)) & /@ Range@n,
  r  = Array[1 &, n]},
 Column@{LocatorPane[
    Dynamic[pt],
    Framed@Graphics[
      {(*The Arrows*)
       Black, Arrow[{{0, 0}, 1.2 #}] & /@ pt,

       (*The Criteria Numbers*)
       MapIndexed[{Text[Style[#2[[1]],20], #1],Circle[#1,.1]}&, 1.1 rot.#&/@pti],

       (*The Cyan Polygons*)
       FaceForm[None], EdgeForm[Cyan], Polygon[pt #] & /@ Range[.2, 1, .2],

       (*The Points*)
       Black, Dynamic[Point[r = MapThread[#1 Clip[#1.#2, {0, 1}] &, {pti, pt}]]],

       (*The Text legends*)
       Dynamic[posText@ r],

       (*The Red Polygon*)
       EdgeForm[{Red, Thick}], Dynamic[Polygon@r]},

      ImageSize -> 550, PlotRange ->1.5 {{-1, 1}, {-1, 1}}], 
    Appearance -> None],
   (*The Footer*)
   Dynamic[Grid[{Table[Norm@r[[i]], {i, n}]}/Total@(Norm /@ r), Dividers->All]]}]

在此处输入图像描述

在此处输入图像描述

Perhaps something like this:

n = 6;
posText[x_List] := Text[Round[Norm@#/Total@(Norm /@ x), .01], 1.3 #, 
                        Background -> LightRed] & /@ x;
rot = RotationMatrix[Pi/15];
DynamicModule[{
  pt = pti = {Re@#, Im@#} &@(E^(2 I Pi #/n)) & /@ Range@n,
  r  = Array[1 &, n]},
 Column@{LocatorPane[
    Dynamic[pt],
    Framed@Graphics[
      {(*The Arrows*)
       Black, Arrow[{{0, 0}, 1.2 #}] & /@ pt,

       (*The Criteria Numbers*)
       MapIndexed[{Text[Style[#2[[1]],20], #1],Circle[#1,.1]}&, 1.1 rot.#&/@pti],

       (*The Cyan Polygons*)
       FaceForm[None], EdgeForm[Cyan], Polygon[pt #] & /@ Range[.2, 1, .2],

       (*The Points*)
       Black, Dynamic[Point[r = MapThread[#1 Clip[#1.#2, {0, 1}] &, {pti, pt}]]],

       (*The Text legends*)
       Dynamic[posText@ r],

       (*The Red Polygon*)
       EdgeForm[{Red, Thick}], Dynamic[Polygon@r]},

      ImageSize -> 550, PlotRange ->1.5 {{-1, 1}, {-1, 1}}], 
    Appearance -> None],
   (*The Footer*)
   Dynamic[Grid[{Table[Norm@r[[i]], {i, n}]}/Total@(Norm /@ r), Dividers->All]]}]

enter image description here

enter image description here

桃酥萝莉 2024-12-18 17:56:07

也许像这样的

Manipulate[
 DynamicModule[{mags, pts, bkgrnd, corners},
  corners = N@Table[{Sin[2 Pi i/n], Cos[2 Pi i/n]}, {i, n}];
  mags = N@Table[1/n, {n}];
  pts = mags corners;
  bkgrnd = {{FaceForm[Opacity[0]], EdgeForm[Gray], 
     Polygon[ Table[r corners, {r, .2, 1, .2}]]},
    Table[
     Text[Row[{"Criterion ", i}], 
      1.05 corners[[i]], -corners[[i]]], {i, n}]};

  LocatorPane[
   Dynamic[
    pts, (mags = Norm /@ #; mags = mags/Total[mags]; 
      pts = mags corners) &],
   Dynamic@Graphics[{bkgrnd,
      {FaceForm[], EdgeForm[{Thick, Blue}], Polygon[pts]},
      Table[
       Text[NumberForm[mags[[i]], {4, 2}], 
        pts[[i]], -1.8 corners[[i]]], {i, n}]}, PlotRange -> All],
   Appearance -> Graphics[{PointSize[.02], Point[{0, 0}]}]]],

 {{n, 3}, Range[3, 7]}]

屏幕截图:

screenshot

Maybe something like this

Manipulate[
 DynamicModule[{mags, pts, bkgrnd, corners},
  corners = N@Table[{Sin[2 Pi i/n], Cos[2 Pi i/n]}, {i, n}];
  mags = N@Table[1/n, {n}];
  pts = mags corners;
  bkgrnd = {{FaceForm[Opacity[0]], EdgeForm[Gray], 
     Polygon[ Table[r corners, {r, .2, 1, .2}]]},
    Table[
     Text[Row[{"Criterion ", i}], 
      1.05 corners[[i]], -corners[[i]]], {i, n}]};

  LocatorPane[
   Dynamic[
    pts, (mags = Norm /@ #; mags = mags/Total[mags]; 
      pts = mags corners) &],
   Dynamic@Graphics[{bkgrnd,
      {FaceForm[], EdgeForm[{Thick, Blue}], Polygon[pts]},
      Table[
       Text[NumberForm[mags[[i]], {4, 2}], 
        pts[[i]], -1.8 corners[[i]]], {i, n}]}, PlotRange -> All],
   Appearance -> Graphics[{PointSize[.02], Point[{0, 0}]}]]],

 {{n, 3}, Range[3, 7]}]

Screenshot:

screenshot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文